Skip to content

Commit

Permalink
Do not show hidden arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Jun 13, 2024
1 parent 766b1a5 commit 7095200
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 10 additions & 0 deletions docs/examples/complex-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This document contains the help content for the `complex-app` command-line progr

* [`complex-app`](#complex-app)
* [`complex-app test`](#complex-app-test)
* [`complex-app only-hidden-options`](#complex-app-only-hidden-options)

## `complex-app`

Expand All @@ -16,6 +17,7 @@ An example command-line tool
###### **Subcommands:**

* `test` — does testing things
* `only-hidden-options` — Demo that `Options` is not printed if all options are hidden

###### **Arguments:**

Expand Down Expand Up @@ -49,6 +51,14 @@ does testing things



## `complex-app only-hidden-options`

Demo that `Options` is not printed if all options are hidden

**Usage:** `complex-app only-hidden-options`



<hr/>

<small><i>
Expand Down
8 changes: 8 additions & 0 deletions docs/examples/complex_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub struct Cli {
#[arg(short, long, action = clap::ArgAction::Count)]
debug: u8,

#[arg(short, long, hide = true)]
secret_arg: bool,

#[command(subcommand)]
command: Option<Commands>,
}
Expand All @@ -32,6 +35,11 @@ enum Commands {
#[arg(short, long)]
list: bool,
},
/// Demo that `Options` is not printed if all options are hidden
OnlyHiddenOptions {
#[arg(short, long, hide = true)]
secret: bool,
},
}

#[derive(clap::ValueEnum)]
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ fn build_command_markdown(

let non_pos: Vec<_> = command
.get_arguments()
.filter(|arg| !arg.is_positional())
.filter(|arg| !arg.is_positional() && !arg.is_hide_set())
.collect();

if !non_pos.is_empty() {
Expand Down Expand Up @@ -377,9 +377,6 @@ fn build_command_markdown(
}

fn write_arg_markdown(buffer: &mut String, arg: &clap::Arg) -> fmt::Result {
// Markdown list item
write!(buffer, "* ")?;

let value_name: String = match arg.get_value_names() {
// TODO: What if multiple names are provided?
Some([name, ..]) => name.as_str().to_owned(),
Expand All @@ -389,6 +386,8 @@ fn write_arg_markdown(buffer: &mut String, arg: &clap::Arg) -> fmt::Result {
None => arg.get_id().to_string().to_ascii_uppercase(),
};

// Markdown list item
write!(buffer, "* ")?;
match (arg.get_short(), arg.get_long()) {
(Some(short), Some(long)) => {
if arg.get_action().takes_values() {
Expand Down

0 comments on commit 7095200

Please sign in to comment.