Skip to content

Commit 79aa6da

Browse files
committed
Default to formatting current directory and update documentation
1 parent 88a6ea7 commit 79aa6da

2 files changed

Lines changed: 34 additions & 11 deletions

File tree

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,30 @@ You can find binaries for Windows, macOS, and Linux in the [releases tab](https:
3535
- **Arch Linux:** Community maintained AUR Package [gdscript-formatter-bin](https://aur.archlinux.org/packages/gdscript-formatter-bin).
3636
- **Windows:** Community maintained Scoop package (`scoop install` [`extras/gdscript-formatter`](https://github.com/ScoopInstaller/Extras/blob/master/bucket/gdscript-formatter.json))
3737

38+
To recursively format all GDScript files in the current folder, run:
39+
40+
```bash
41+
gdscript-formatter
42+
```
43+
3844
To format a file, run:
3945

4046
```bash
4147
gdscript-formatter path/to/file.gd
4248
```
4349

50+
To recursively format all GDScript files in another folder, run:
51+
52+
```bash
53+
gdscript-formatter path/to/folder
54+
```
55+
56+
You can also pass multiple files or folders:
57+
58+
```bash
59+
gdscript-formatter path/to/file.gd path/to/folder
60+
```
61+
4462
Use the `--safe` flag to add a safety check that prevents overwriting files if the formatter makes unwanted changes (any change that would modify the code meaning, like removing a piece of functional code). This is useful when you use a development version of the formatter or when you want to be extra careful:
4563

4664
```bash
@@ -53,7 +71,9 @@ Format with check mode, to use in a build system (exit code 1 if changes needed)
5371
gdscript-formatter --check path/to/file.gd
5472
```
5573

56-
To see other possible options, run `gdscript-formatter` without any arguments.
74+
It will print the files that need to be formatted.
75+
76+
To see other possible options, run `gdscript-formatter --help`.
5777

5878
## Linting GDScript files
5979

src/main.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
path::PathBuf,
55
};
66

7-
use clap::{CommandFactory, Parser};
7+
use clap::Parser;
88
use rayon::prelude::*;
99

1010
use gdscript_formatter::linter::rule_config::{
@@ -128,13 +128,6 @@ enum Commands {
128128
}
129129

130130
fn main() -> Result<(), Box<dyn std::error::Error>> {
131-
// If there are no arguments and nothing piped from stdin, print the help message
132-
if env::args().len() == 1 && io::stdin().is_terminal() {
133-
Args::command().print_help()?;
134-
println!();
135-
return Ok(());
136-
}
137-
138131
let args = Args::parse();
139132

140133
// Handle lint subcommand
@@ -182,7 +175,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
182175
safe: args.safe,
183176
};
184177

185-
if args.input.is_empty() {
178+
// Is terminal allows us to distinguish between formatting piped code from
179+
// stdin automatically finding all gdscript files from the current directory
180+
if args.input.is_empty() && !io::stdin().is_terminal() {
186181
let mut input_content = String::new();
187182
io::stdin()
188183
.read_to_string(&mut input_content)
@@ -204,7 +199,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
204199
return Ok(());
205200
}
206201

207-
let input_gdscript_files = find_gdscript_files(&args.input)?;
202+
let input_paths = if args.input.is_empty() {
203+
vec![
204+
env::current_dir()
205+
.map_err(|error| format!("Failed to get current directory: {}", error))?,
206+
]
207+
} else {
208+
args.input
209+
};
210+
let input_gdscript_files = find_gdscript_files(&input_paths)?;
208211

209212
let total_files = input_gdscript_files.len();
210213

0 commit comments

Comments
 (0)