Skip to content

Commit 530f3f7

Browse files
Improve --help and -h (#129)
* Turn on wrapping of CLI help Fixes #127 * rewrite some of the help text While working on issue #127 I was poking at the help text. I decided to keep the changes and submit them in a separate commit from the real committed fix. * Apply suggestions from code review --------- Co-authored-by: Nathan GDQuest <nathan@gdquest.com>
1 parent 15dfa59 commit 530f3f7

3 files changed

Lines changed: 65 additions & 50 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repository = "https://github.com/gdquest/gdscript-formatter"
88
default-run = "gdscript-formatter"
99

1010
[dependencies]
11-
clap = { version = "4.0", features = ["derive"] }
11+
clap = { version = "4.0", features = ["derive", "wrap_help"] }
1212
topiary-core = { git = "https://github.com/tweag/topiary", rev = "5081ccef9245fe56c2b3e2a7ced52277eda45825" }
1313
tree-sitter-gdscript = { git = "https://github.com/PrestonKnopp/tree-sitter-gdscript.git", rev = "0b9f60ebaa1c31f5153dd3a3b283ca0725734378" }
1414
regex = "1.11"

src/main.rs

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,67 +28,81 @@ struct FormatterOutput {
2828
}
2929

3030
#[derive(Parser)]
31+
/// A GDScript formatter following the official style guide.
32+
///
33+
/// This program formats GDScript files with a consistent style and indentation
34+
/// using Topiary and Tree-sitter.
35+
///
36+
/// By default, the formatter overwrites input files with the formatted code.
37+
/// Use the --stdout flag to output to standard output instead.
38+
///
39+
/// The latest version of the GDScript style guide can be found at:
40+
/// https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_styleguide.html
3141
#[clap(
32-
about = "A GDScript code formatter using Topiary and Tree-sitter",
3342
// Use the version number directly from Cargo.toml at compile time
34-
version = env!("CARGO_PKG_VERSION"),
35-
long_about = "Format GDScript files with consistent style and indentation. \
36-
By default, the formatter overwrites input files with the formatted code. \
37-
Use --stdout to output to standard output instead."
43+
version = env!("CARGO_PKG_VERSION")
3844
)]
3945
struct Args {
40-
#[arg(
41-
help = "Input GDScript file(s) to format. If no file path is provided, the program reads from standard input and outputs to standard output.",
42-
value_name = "FILES"
43-
)]
46+
/// The GDScript file(s) to format. If no file paths are provided, the
47+
/// program reads from standard input and outputs to standard output.
48+
#[arg(value_name = "FILES")]
4449
input: Vec<PathBuf>,
50+
4551
#[command(subcommand)]
4652
command: Option<Commands>,
47-
#[arg(
48-
long,
49-
help = "Output formatted code to stdout instead of overwriting the input file. \
50-
If multiple input files are provided, each file's content is preceded by a comment indicating the file name, with the form \
51-
#--file:<file_path> \
52-
This flag is ignored when reading from stdin (stdout is always used)."
53-
)]
53+
54+
/// Output formatted code to stdout without changing FILES.
55+
///
56+
/// If multiple input files are provided, each file's content is preceded
57+
/// by the line "#--file:<file_path>".
58+
///
59+
/// This flag is ignored when reading from stdin since stdout is always
60+
/// used.
61+
#[arg(long)]
5462
stdout: bool,
55-
#[arg(
56-
short,
57-
long,
58-
help = "Check if the file is already formatted without making changes. \
59-
Exits with code 0 if the file is already formatted and 1 if it's not formatted"
60-
)]
63+
64+
/// Check if FILES are formatted, making no changes.
65+
///
66+
/// Exits with code 0 if the file is already formatted and 1 if it's not
67+
/// formatted.
68+
#[arg(short, long)]
6169
check: bool,
62-
#[arg(
63-
long,
64-
help = "Use spaces for indentation instead of tabs. \
65-
The number of spaces is controlled by --indent-size"
66-
)]
70+
71+
/// Use spaces for indentation instead of tabs.
72+
///
73+
/// Use --indent-size to set the number of spaces to use as indentation.
74+
#[arg(long)]
6775
use_spaces: bool,
68-
#[arg(
69-
long,
70-
help = "Number of spaces to use for each indentation level when --use-spaces is enabled. \
71-
Has no effect without the --use-spaces flag.",
72-
default_value = "4",
73-
value_name = "NUM"
74-
)]
76+
77+
/// Set how many spaces to use for indentation.
78+
///
79+
/// Has no effect without the --use-spaces flag.
80+
#[arg(long, default_value = "4", value_name = "NUM")]
7581
indent_size: usize,
76-
#[arg(
77-
long,
78-
help = "Reorder source-level declarations (signals, properties, methods, etc.) according to the official GDScript style guide. \
79-
This is optional and applies after the main formatting pass."
80-
)]
82+
83+
/// Reorder code to follow the official GDScript style guide.
84+
///
85+
/// Reorder source-level declarations (signals, properties, methods, etc.)
86+
/// in this order: signals, enums, constants, properties, static and built-in
87+
/// virtual methods, public methods, pseudo-private methods, and sub-classes.
88+
///
89+
/// If enabled, reordering happens after formatting the code.
90+
#[arg(long)]
8191
reorder_code: bool,
82-
#[arg(
83-
short,
84-
long,
85-
help = "Enable safe mode. This mode ensures that after formatting, the code still has the same syntax and structure \
86-
as when initially parsed. If not, formatting is canceled.\n \
87-
But this offers a good amount protection against the formatter failing on new syntax \
88-
at the cost of a small little extra running time. Currently incompatible with --reorder-code.\n \
89-
WARNING: this is not a perfect solution. Some rare edge cases may still lead to syntax changes.",
90-
conflicts_with = "reorder_code"
91-
)]
92+
93+
/// Enable safe mode.
94+
///
95+
/// This mode ensures that after formatting, the code still has the same
96+
/// syntax and structure as when initially parsed. If not, formatting is
97+
/// canceled.
98+
///
99+
/// This offers a good amount protection against the formatter failing
100+
/// on new syntax at the cost of a small little extra running time.
101+
/// Currently incompatible with --reorder-code.
102+
///
103+
/// WARNING: this is not a perfect solution. Some rare edge cases may still
104+
/// lead to syntax changes.
105+
#[arg(short, long, conflicts_with = "reorder_code")]
92106
safe: bool,
93107
}
94108

0 commit comments

Comments
 (0)