-
Hi all, I'm trying to have it so that my program can be run with or without a subcommand. If a subcommand is passed, the global required arguments should no longer be required. If there is no subcommand, the global required arguments should remain required. This is what I've got: use clap::{Parser, Subcommand};
#[derive(Subcommand, Clone)]
pub enum Commands {
/// Print a config template.
ConfigTemplate,
}
#[derive(Parser)]
#[command(arg_required_else_help(true))]
#[command(subcommand_negates_reqs(true))]
#[command(args_conflicts_with_subcommands(true))]
pub struct Cli {
/// Output what would happen, but don't actually submit to Clockify.
#[arg(short, long)]
pub dry_run: bool,
#[command(subcommand)]
pub command: Option<Commands>,
/// The Jira timesheet CSV export file. Use '-' to read from stdin.
pub file: String,
}
The multiple
Which is still requiring the Is there something I'm doing wrong, or is this a bug? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
That error isn't coming from clap's validation logic but the derive when it is trying to fill in the Options
|
Beta Was this translation helpful? Give feedback.
That error isn't coming from clap's validation logic but the derive when it is trying to fill in the
file
field within the struct.Options
Option<String>
and explicitly mark it as required.GlobalArgs
struct that you flatten withargs: Option<GlobalArgs>
args_conflicts_with_subcommands