Skip to content

Optional flag at top-level conflicts with required top-level subcommands #5353

Answered by epage
fooblinator asked this question in Q&A
Discussion options

You must be logged in to vote

This appears to be a bug in clap. You should be able to do:

#!/usr/bin/env nargo
---
[dependencies]
clap = { version = "4", features = ["derive"] }
---

use clap::Parser;
use clap::Subcommand;

#[derive(Parser, Debug)]
#[command(about, version)]
#[command(
    arg_required_else_help = false,
    args_conflicts_with_subcommands = true,
)]
struct Cli {
    /// Print about
    #[arg(long, short)]
    about: bool,

    #[command(subcommand)]
    commands: Option<CliCmds>, // or `commands: Option<CliCmds>,` ???
}

#[derive(Subcommand, Debug)]
#[command(subcommand_required = true)]
enum CliCmds {
    #[command(subcommand)]
    Manage(CliManageCmds),

    #[command(subcommand)]
    Track(CliTrac…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fooblinator
Comment options

Answer selected by fooblinator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants