"address of value to print")) .group( ArgGroup::new("format") .arg(arg!(i" /> "address of value to print")) .group( ArgGroup::new("format") .arg(arg!(i" /> "address of value to print")) .group( ArgGroup::new("format") .arg(arg!(i"/>

trying to get clap builder to accept arg! with ArgGroup, cannot work out what I am missing

32 Views Asked by At

this code

    .subcommand(
        Command::new("print")
            .alias("p")
            .arg(arg!(<address>  "address of value to print"))
            .group(
                ArgGroup::new("format")
                    .arg(arg!(integer: -i   "int"))
                    .arg(arg!(pointe: -p   "pointer"))
                    .required(true),
            )
            .about("delete breakpoint")
            .help_template(APPLET_TEMPLATE),
    )

generates a storm of errors I dont understand

   --> src\shell.rs:388:34
    |
388 | ...                   .arg(arg!(integer: -i   "int"))
    |                        --- ^^^^^^^^^^^^^^^^^^^^^^^^^
    |                        |   |
    |                        |   the trait `From<Arg>` is not implemented for `Id`
    |                        |   this tail expression is of type `Arg`
    |                        required by a bound introduced by this call
    |
    = help: the following other types implement trait `From<T>`:
              <Id as From<Str>>
              <Id as From<&Id>>
              <Id as From<&Str>>
              <Id as From<&&'static str>>
              <Id as From<&'static str>>
    = note: required for `Arg` to implement `Into<Id>`
    = note: required for `Arg` to implement `IntoResettable<Id>`
note: required by a bound in `ArgGroup::arg`
   --> C:\Users\paulm\.cargo\registry\src\index.crates.io-6f17d22bba15001f\clap_builder-4.4.12\src\builder\arg_group.rs:157:39
    |
157 |     pub fn arg(mut self, arg_id: impl IntoResettable<Id>) -> Self {
    |                                       ^^^^^^^^^^^^^^^^^^ required by this bound in `ArgGroup::arg`

error[E0277]: the trait bound `Id: From<Arg>` is not satisfied
   --> src\shell.rs:389:34
    |
389 | ...                   .arg(arg!(pointe: -p   "pointer"))
    |                        --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                        |   |
    |                        |   the trait `From<Arg>` is not implemented for `Id`
    |                        |   this tail expression is of type `Arg`
    |                        required by a bound introduced by this call
    |
    = help: the following other types implement trait `From<T>`:
              <Id as From<Str>>
              <Id as From<&Id>>
              <Id as From<&Str>>
              <Id as From<&&'static str>>
              <Id as From<&'static str>>
    = note: required for `Arg` to implement `Into<Id>`
    = note: required for `Arg` to implement `IntoResettable<Id>`
note: required by a bound in `ArgGroup::arg`
   --> C:\Users\paulm\.cargo\registry\src\index.crates.io-6f17d22bba15001f\clap_builder-4.4.12\src\builder\arg_group.rs:157:39
    |
157 |     pub fn arg(mut self, arg_id: impl IntoResettable<Id>) -> Self {
    |                                       ^^^^^^^^^^^^^^^^^^ required by this bound in `ArgGroup::arg`

I think its trying to say that it cant work out an Id from the arg! macro invocation, but I have tried many combinations of arg! syntax and all produce the same errors.

  • clap 4.4.12
  • clap derive 4.4.7
1

There are 1 best solutions below

0
pm100 On

I see now. The args have to be specified individually then placed in a group

like this

.subcommand(
    Command::new("print")
        .alias("p")
        .arg(arg!(<address>  "address of value to print"))
        .arg(arg!(asint: -i "int"))
        .arg(arg!(aspointer: -p   "pointer"))
        .arg(arg!(astring: -s   "string"))
        .group(
            ArgGroup::new("format")
                .args(["asint", "aspointer", "astring"])
                .required(true),
        )
        .about("delete breakpoint")
        .help_template(APPLET_TEMPLATE),
)