Skip to content

clap_usage generate invalid KDL document with Option<bool> #321

@koitococo

Description

@koitococo

I use clap to build my cli app, and clap_usage to generate a KDL document for completions. Below is a minimum reproduction:

#[derive(clap::Parser)]
struct Args {
    #[clap(short = 'b')]
    this_is_a_bool: Option<bool>,
}

fn main() {
    use clap::CommandFactory as _;
    clap_usage::generate(&mut Args::command(), "demo", &mut std::io::stdout());
}

which produces:

name demo
bin demo
usage "Usage: demo [OPTIONS]"
flag -b {
    arg <THIS_IS_A_BOOL> {
        choices true false
    }
}

When invoking usage complete-word --shell fish -s "$(cargo run)", usage complains:

  × Failed to parse KDL document

Error: 
  × Expected identifier string
   ╭─[6:17]
 5 │     arg <THIS_IS_A_BOOL> {
 6 │         choices true false
   ·                 ──┬─
   ·                   ╰── not identifier string
 7 │     }
   ╰────

Error: 
  × Expected identifier string
   ╭─[6:22]
 5 │     arg <THIS_IS_A_BOOL> {
 6 │         choices true false
   ·                      ──┬──
   ·                        ╰── not identifier string
 7 │     }
   ╰────

clap and clap_usage is the latest version:

[dependencies]
clap = "4.5.46"
clap_usage = "2.0.3"

It only happens to Option<bool>. If replace it with bool or Option<SomeValueEnums>, everything seems ok.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions