@@ -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) ]
3945struct 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