command_group

Macro command_group 

Source
macro_rules! command_group {
    (
        $(#[$attrs:meta])*
        $vis:vis enum $name:ident {
            $(
                $variant:ident($path:path)
            ),*
        }
    ) => { ... };
}
Expand description

Make an enum implementing Command where its every variant have only one field implements Commnad. The enum will provide a parse function matching each variant’s name directly.

Example:

#[derive(Command)]
struct A;

#[derive(Command)]
struct B;


command_group! {
    enum Root {
        A(A),
        B(B)
    }
}

assert_eq!(Ok(Root::A(A)), Root::parse(&[CommandFragment::Select("a".to_string()), CommandFragment::Execute(vec![])]));
assert_eq!(Ok(Root::B(B)), Root::parse(&[CommandFragment::Select("b".to_string()), CommandFragment::Execute(vec![])]));
assert_eq!(Err(CommandParseError::UnknownCommand(&"c".to_string())), Root::parse(&[CommandFragment::Select("c".to_string()), CommandFragment::Execute(vec![])]));