Skip to content

Commit 5c8eaf6

Browse files
willemnealgitbutler-client
authored andcommitted
feat: add support for argument aliases in markdown output
Currently it adds the alias after the current options before the help doc. Open to other suggestions.
1 parent 1e1ae46 commit 5c8eaf6

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎docs/examples/complex-app-custom.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ An example command-line tool
2121

2222
###### **Options:**
2323

24-
* `-c`, `--config <FILE>` — Sets a custom config file
24+
* `-c`, `--config <FILE>` Aliases: `configuration` — Sets a custom config file
2525
* `--target <TARGET>`
2626

2727
Default value: `local`

‎docs/examples/complex-app.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ An example command-line tool
2727

2828
###### **Options:**
2929

30-
* `-c`, `--config <FILE>` — Sets a custom config file
30+
* `-c`, `--config <FILE>` Aliases: `configuration` — Sets a custom config file
3131
* `--target <TARGET>`
3232

3333
Default value: `local`

‎docs/examples/complex_app.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Cli {
1212
name: Option<String>,
1313

1414
/// Sets a custom config file
15-
#[arg(short, long, value_name = "FILE")]
15+
#[arg(short, long, value_name = "FILE", visible_alias = "configuration")]
1616
config: Option<PathBuf>,
1717

1818
#[arg(long, default_value = "local")]

‎src/lib.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ fn write_arg_markdown(buffer: &mut String, arg: &clap::Arg) -> fmt::Result {
459459
},
460460
(None, Some(long)) => {
461461
if arg.get_action().takes_values() {
462-
write!(buffer, "`--{} <{value_name}>`", long)?
462+
write!(buffer, "`--{long} <{value_name}>`")?
463463
} else {
464-
write!(buffer, "`--{}`", long)?
464+
write!(buffer, "`--{long}`")?
465465
}
466466
},
467467
(None, None) => {
@@ -471,6 +471,18 @@ fn write_arg_markdown(buffer: &mut String, arg: &clap::Arg) -> fmt::Result {
471471
},
472472
}
473473

474+
if let Some(aliases) = arg.get_visible_aliases() {
475+
if !aliases.is_empty() {
476+
write!(buffer, " Aliases: ")?;
477+
for (i, alias) in aliases.into_iter().enumerate() {
478+
if i > 0 {
479+
write!(buffer, ", ")?;
480+
}
481+
write!(buffer, "`{alias}`")?;
482+
}
483+
}
484+
}
485+
474486
if let Some(help) = arg.get_long_help() {
475487
// TODO: Parse formatting in the string
476488
buffer.push_str(&indent(&help.to_string(), " — ", " "))

0 commit comments

Comments
 (0)