Skip to content

Commit 0865dcb

Browse files
authored
Merge pull request #846 from epage/help
fix(cli): Improve help layout
2 parents 4d8497c + 21c88ca commit 0865dcb

File tree

2 files changed

+76
-20
lines changed

2 files changed

+76
-20
lines changed

crates/typos-cli/src/bin/typos-cli/args.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,60 +42,67 @@ pub(crate) struct Args {
4242
#[arg(default_value = ".")]
4343
pub(crate) path: Vec<std::path::PathBuf>,
4444

45+
/// The approximate number of threads to use.
46+
#[arg(short = 'j', long = "threads", default_value = "0")]
47+
pub(crate) threads: usize,
48+
4549
/// Custom config file
46-
#[arg(short = 'c', long = "config")]
50+
#[arg(short = 'c', long = "config", help_heading = "Config")]
4751
pub(crate) custom_config: Option<std::path::PathBuf>,
4852

4953
/// Ignore implicit configuration files.
50-
#[arg(long)]
54+
#[arg(long, help_heading = "Config")]
5155
pub(crate) isolated: bool,
5256

57+
#[command(flatten, next_help_heading = "Config")]
58+
pub(crate) config: ConfigArgs,
59+
5360
/// Print a diff of what would change
54-
#[arg(long, group = "mode")]
61+
#[arg(long, group = "mode", help_heading = "Mode")]
5562
pub(crate) diff: bool,
5663

5764
/// Write fixes out
58-
#[arg(long, short = 'w', group = "mode")]
65+
#[arg(long, short = 'w', group = "mode", help_heading = "Mode")]
5966
pub(crate) write_changes: bool,
6067

6168
/// Debug: Print each file that would be spellchecked.
62-
#[arg(long, group = "mode")]
69+
#[arg(long, group = "mode", help_heading = "Mode")]
6370
pub(crate) files: bool,
6471

6572
/// Debug: Print each file's type
66-
#[arg(long, group = "mode")]
73+
#[arg(long, group = "mode", help_heading = "Mode")]
6774
pub(crate) file_types: bool,
6875

6976
/// Debug: Print each identifier that would be spellchecked.
70-
#[arg(long, group = "mode")]
77+
#[arg(long, group = "mode", help_heading = "Mode")]
7178
pub(crate) identifiers: bool,
7279

7380
/// Debug: Print each word that would be spellchecked.
74-
#[arg(long, group = "mode")]
81+
#[arg(long, group = "mode", help_heading = "Mode")]
7582
pub(crate) words: bool,
7683

7784
/// Write the current configuration to file with `-` for stdout
78-
#[arg(long, group = "mode")]
85+
#[arg(long, group = "mode", help_heading = "Mode")]
7986
pub(crate) dump_config: Option<std::path::PathBuf>,
8087

8188
/// Show all supported file types.
82-
#[arg(long, group = "mode")]
89+
#[arg(long, group = "mode", help_heading = "Mode")]
8390
pub(crate) type_list: bool,
8491

85-
#[arg(long, value_enum, ignore_case = true, default_value("long"))]
92+
/// Render style for messages
93+
#[arg(
94+
long,
95+
value_enum,
96+
ignore_case = true,
97+
default_value("long"),
98+
help_heading = "Output"
99+
)]
86100
pub(crate) format: Format,
87101

88-
/// The approximate number of threads to use.
89-
#[arg(short = 'j', long = "threads", default_value = "0")]
90-
pub(crate) threads: usize,
91-
92-
#[command(flatten)]
93-
pub(crate) config: ConfigArgs,
94-
95-
#[command(flatten)]
102+
#[command(flatten, next_help_heading = "Output")]
96103
pub(crate) color: colorchoice_clap::Color,
97104

98-
#[command(flatten)]
105+
#[command(flatten, next_help_heading = "Output")]
99106
pub(crate) verbose: clap_verbosity_flag::Verbosity,
100107
}
101108

@@ -126,6 +133,7 @@ pub(crate) struct FileArgs {
126133
#[arg(long, overrides_with("unicode"))]
127134
no_unicode: bool,
128135

136+
/// Language locale to suggest corrections for
129137
#[arg(long)]
130138
#[arg(
131139
value_parser = clap::builder::PossibleValuesParser::new(config::Locale::variants())

crates/typos-cli/tests/cmd/help.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
bin.name = "typos"
2+
args = "--help"
3+
stdout = """
4+
Source Code Spelling Correction
5+
6+
Usage: typos[EXE] [OPTIONS] [PATH]...
7+
8+
Arguments:
9+
[PATH]... Paths to check with `-` for stdin [default: .]
10+
11+
Options:
12+
-j, --threads <THREADS> The approximate number of threads to use [default: 0]
13+
-h, --help Print help
14+
-V, --version Print version
15+
16+
Config:
17+
-c, --config <CUSTOM_CONFIG> Custom config file
18+
--isolated Ignore implicit configuration files
19+
--exclude <GLOB> Ignore files & directories matching the glob
20+
--hidden Search hidden files and directories
21+
--no-ignore Don't respect ignore files
22+
--no-ignore-dot Don't respect .ignore files
23+
--no-ignore-global Don't respect global ignore files
24+
--no-ignore-parent Don't respect ignore files in parent directories
25+
--no-ignore-vcs Don't respect ignore files in vcs directories
26+
--binary Search binary files
27+
--no-check-filenames Skip verifying spelling in file names
28+
--no-check-files Skip verifying spelling in files
29+
--no-unicode Only allow ASCII characters in identifiers
30+
--locale <LOCALE> Language locale to suggest corrections for [possible values: en, en-us, en-gb, en-ca, en-au]
31+
32+
Mode:
33+
--diff Print a diff of what would change
34+
-w, --write-changes Write fixes out
35+
--files Debug: Print each file that would be spellchecked
36+
--file-types Debug: Print each file's type
37+
--identifiers Debug: Print each identifier that would be spellchecked
38+
--words Debug: Print each word that would be spellchecked
39+
--dump-config <DUMP_CONFIG> Write the current configuration to file with `-` for stdout
40+
--type-list Show all supported file types
41+
42+
Output:
43+
--format <FORMAT> Render style for messages [default: long] [possible values: silent, brief, long, json]
44+
--color <WHEN> Controls when to use color [default: auto] [possible values: auto, always, never]
45+
-v, --verbose... More output per occurrence
46+
-q, --quiet... Less output per occurrence
47+
"""
48+
stderr = ""

0 commit comments

Comments
 (0)