Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 14, 2024
1 parent 9070347 commit e663005
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cli/src/cli/generate/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
```
"#;

Expand Down
5 changes: 5 additions & 0 deletions examples/mise.gen.usage.kdl
Original file line number Diff line number Diff line change
@@ -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] <COMMAND>"
flag "-C,--cd" help="Change directory before running command" global=true {
arg "<DIR>"
}
Expand Down Expand Up @@ -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"

7 changes: 7 additions & 0 deletions src/parse/flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Flag {
pub global: bool,
pub count: bool,
pub arg: Option<Arg>,
pub default: Option<String>,
}

impl Flag {
Expand Down Expand Up @@ -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}"),
}
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
}
}
}
Expand Down

0 comments on commit e663005

Please sign in to comment.