[Feature request] Alias a single flag to a set of multiple flags
gfscott opened this issue · comments
Do you want to request a feature or report a bug?
Feature request!
What is the current behavior?
Currently, it's easy to declare flag aliases on a 1:1 basis:
User input | Alias that runs |
---|---|
command --old-flag |
command --new-flag |
What is the expected behavior?
What I'd like to be able to do is declare flag aliases on a 1:many
basis — create a flag that aliases multiple existing flags, to provide users with shortcuts to a sensible set of options:
User input | Aliased flags that run |
---|---|
order --combo |
order --burger --fries --shake=strawberry |
Purely spitballing, but here's an idea of how I might reasonably expect to configure this:
export default class Order extends Command {
static description = 'Place your order';
static flags = {
burger: Flags.string({/***/}),
fries: Flags.boolean({/***/}),
shake: Flags.string({/***/}),
combo: Flags.boolean({
default: false,
description: 'The chef’s special :)',
groupAlias: [
{ flag: 'burger' }, // flag has default value, therefore no option required
{ flag: 'fries' }, // flag is a boolean, no option required
{
flag: 'shake',
option: 'strawberry' // flag is a string with no default value, so option is required
},
]
}),
}
}
I think something like this would make it easier to support common use cases and workflows, while preserving composability and granularity for power users. Thanks!
@gfscott This is a neat idea.
We've been considering adding a preparse
hook that would allow people to manipulate the raw flags and args before they're parsed. I think such a feature would be able to support your idea. Essentially you would see if --combo
is present and then add the other flags to the set of flags that will be parsed.
Implementing that feature is behind a few things other things on our roadmap so I'll keep this feature request open in the meantime