Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Alias a single flag to a set of multiple flags #962

Closed
gfscott opened this issue Feb 20, 2024 · 1 comment · Fixed by #1005
Closed

[Feature request] Alias a single flag to a set of multiple flags #962

gfscott opened this issue Feb 20, 2024 · 1 comment · Fixed by #1005

Comments

@gfscott
Copy link

gfscott commented Feb 20, 2024

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!

@mdonnalley mdonnalley transferred this issue from oclif/oclif Feb 20, 2024
@mdonnalley
Copy link
Contributor

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants