diff --git a/cli/src/cli/generate/markdown.rs b/cli/src/cli/generate/markdown.rs index f0ccf29..b2bab60 100644 --- a/cli/src/cli/generate/markdown.rs +++ b/cli/src/cli/generate/markdown.rs @@ -148,14 +148,14 @@ impl Markdown { } const USAGE_TITLE_TEMPLATE: &str = r#" -# {spec.name} +# {{spec.name}} "#; const USAGE_OVERVIEW_TEMPLATE: &str = r#" ## Usage ```bash -{{spec.bin}} [flags] [args] +{{spec.usage}} ``` "#; diff --git a/examples/mise.gen.usage.kdl b/examples/mise.gen.usage.kdl index 5206643..dc0f3b3 100644 --- a/examples/mise.gen.usage.kdl +++ b/examples/mise.gen.usage.kdl @@ -1,5 +1,9 @@ name "mise" bin "mise" +version "2024.1.19-DEBUG macos-arm64 (4b93e5e 2024-01-14)" +about "The front-end to your dev env" +long_about "mise is a tool for managing runtime versions. https://github.com/jdx/mise\n\nIt's a replacement for tools like nvm, nodenv, rbenv, rvm, chruby, pyenv, etc.\nthat works for any language. It's also great for managing linters/tools like\njq and shellcheck.\n\nIt is inspired by asdf and uses asdf's plugin ecosystem under the hood:\nhttps://asdf-vm.com/" +usage "Usage: mise [OPTIONS] " flag "-C,--cd" help="Change directory before running command" global=true { arg "" } @@ -443,3 +447,4 @@ cmd "render-completion" hide=true help="Generate shell completions" { } cmd "render-help" hide=true help="internal command to generate markdown from help" cmd "render-mangen" hide=true help="internal command to generate markdown from help" + diff --git a/src/parse/flag.rs b/src/parse/flag.rs index 9600241..38adc4f 100644 --- a/src/parse/flag.rs +++ b/src/parse/flag.rs @@ -23,6 +23,7 @@ pub struct Flag { pub global: bool, pub count: bool, pub arg: Option, + pub default: Option, } impl Flag { @@ -95,6 +96,7 @@ impl TryFrom<&KdlNode> for Flag { "hide" => flag.hide = v.ensure_bool()?, "global" => flag.global = v.ensure_bool()?, "count" => flag.count = v.ensure_bool()?, + "default" => flag.default = v.ensure_string().map(Some)?, k => bail_parse!(v.entry, "unsupported key {k}"), } } @@ -147,6 +149,10 @@ impl From<&clap::Arg> for Flag { c.get_action(), clap::ArgAction::Count | clap::ArgAction::Append ); + let default = c + .get_default_values() + .first() + .map(|s| s.to_string_lossy().to_string()); let short = c.get_short_and_visible_aliases().unwrap_or_default(); let long = c .get_long_and_visible_aliases() @@ -182,6 +188,7 @@ impl From<&clap::Arg> for Flag { global: c.is_global_set(), arg, count: matches!(c.get_action(), clap::ArgAction::Count), + default, } } }