From 5c61462a3429f45db7d2c8da5e8cbb7edcca1abf Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Thu, 13 Jun 2024 14:41:35 -0700 Subject: [PATCH] Do not show hidden arguments Fixes https://github.com/ConnorGray/clap-markdown/issues/18 --- docs/examples/complex-app.md | 10 ++++++++++ docs/examples/complex_app.rs | 8 ++++++++ src/lib.rs | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/examples/complex-app.md b/docs/examples/complex-app.md index 0c9aad8..a357309 100644 --- a/docs/examples/complex-app.md +++ b/docs/examples/complex-app.md @@ -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` @@ -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:** @@ -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` + + +
diff --git a/docs/examples/complex_app.rs b/docs/examples/complex_app.rs index ca7e437..021be97 100644 --- a/docs/examples/complex_app.rs +++ b/docs/examples/complex_app.rs @@ -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, } @@ -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)] diff --git a/src/lib.rs b/src/lib.rs index 05f5299..652c234 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -304,7 +304,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() {