Clap Derive - set default value for vec<u32>

On the command line

prog -arg1 11 22 33

works and arg1 = [11,22,33],

dbg!(arg1):

arg1: Some(
    [
        11,
        22,
        33
    ],

trying to set a default value like [66,77]...

Basic arg

    #[arg(long, required=false, num_args = 0..7)]
    pub(crate) arg1: Option<Vec<u32>>,

add:
default_values = [28,29])]
^^^^^^^^^^^^^^ the trait From<{integer}> is not implemented for clap::builder::OsStr

add:
default_values_t = [28,29])]
^^^^^^^^^^^^^^^ error: #[arg(default_values_t)] can be used only on Vec types

you should wrote

 #[arg(short, long, default_values_t = [66,77])]
pub(crate) arg1: Vec<u32>,

You should use Vec<u32> rather than Option<_>

Excellent. Thank you very much for your help.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.