bpaf icon indicating copy to clipboard operation
bpaf copied to clipboard

Derive attribute to make command enum

Open imsamuka opened this issue 1 year ago • 6 comments

I searched a way to do this but i couldn't. I may have missed it, since the derive docs and naming are very confusing, at least for me.

What i want is a macro attribute (e.g. command_enum) as the other Generated function types that makes the following conversion:

Right now (version 0.7.2)

#[derive(Debug, Clone, Bpaf)]
pub enum MyCommand {
    /// List your accounts
    #[bpaf(command)]
    Accounts,
    /// Login into a account
    #[bpaf(command)]
    Login,
    /// Logout of a account
    #[bpaf(command)]
    Logout {
        no_save: bool
    },
    /// Change status
    #[bpaf(command)]
    Status,
    /// Force save current state
    #[bpaf(command)]
    Save,
}

Proposed

#[derive(Debug, Clone, Bpaf)]
#[bpaf(command_enum)]
pub enum MyCommand {
    /// List your accounts
    Accounts,
    /// Login into a account
    Login,
    /// Logout of a account
    Logout {
        no_save: bool
    },
    /// Change status
    Status,
    /// Force save current state
    Save,
}

imsamuka avatar Mar 05 '23 00:03 imsamuka