d47081
February 12, 2025, 4:37pm
1
Could somebody please give me short answer:
should I handle data type from CLI input like -i false
or I forgot to derive something here:
use clap::Parser;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Argument {
#[arg(short, long, default_value_t = true)]
pub index: bool,
Jesper
February 12, 2025, 4:50pm
2
No argument, you just do -i
and it will be set false...
1 Like
d47081
February 12, 2025, 4:56pm
3
thank you for tip, but in my case empty -i
set the value as true
in debug
when I set annotation to #[arg(short, long, default_value_t = false)]
then it works, but I want have it enabled by default (true
when no arguments)
erelde
February 12, 2025, 5:06pm
4
You need to change the default action for bool. The default is to SetTrue. You want to set the default value to true and set the action to SetFalse.
struct Foo {
#[arg(short, long, action = clap::ArgAction::SetFalse, default_value_t = true)]
index: bool,
}
1 Like
d47081
February 12, 2025, 5:09pm
5
Really, thank you much!
But now I think that should rename this option as -i
maybe really mean -i=true
haha