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

Aliases for subcommands #469

Closed
hoodie opened this issue Mar 29, 2016 · 7 comments
Closed

Aliases for subcommands #469

hoodie opened this issue Mar 29, 2016 · 7 comments
Labels
A-parsing Area: Parser's logic and needs it changed somehow. S-waiting-on-decision Status: Waiting on a go/no-go before implementing

Comments

@hoodie
Copy link
Contributor

hoodie commented Mar 29, 2016

Hi, is there a way to alias subcommands, perhaps even with preset configuration?
I'm thinking of something as simple as making tool list equivalent to tool ls,
but also something like tool csv meaning tool list --tabular --separator ";" --colors off.

This would allow turning certain configurations of a subcommand into their own subcommand.

@kbknapp
Copy link
Member

kbknapp commented Mar 29, 2016

Right now there isn't. If you're on Linux or OSX, shell aliases do exactly that though.

@hoodie
Copy link
Contributor Author

hoodie commented Mar 29, 2016

I know, I thought of something internal though, so you could use one subcommand as a preconfigured shortcut to another. Thor does something similar, there you can invoke another :subcommand with a list of set parameters.

@kbknapp
Copy link
Member

kbknapp commented Mar 30, 2016

I can put this on the issue tracker, but there are a few issues in priority over it so it could be a while. I'll have to play with some implementations to see how it works out.

I'm not super familiar with Thor so I'll into that too. Thanks!

@kbknapp kbknapp added T: new feature S-waiting-on-decision Status: Waiting on a go/no-go before implementing A-parsing Area: Parser's logic and needs it changed somehow. labels Mar 30, 2016
@hoodie
Copy link
Contributor Author

hoodie commented Mar 30, 2016

Perhaps it's just a documentation thing, it would only by nice to be able to manually construct ArgMatches nicer, but this is not so super important, as it can be abstracted around. Thank you for your consideration though 👏

@kbknapp
Copy link
Member

kbknapp commented Mar 30, 2016

If the alias is known beforehand, you can just route calls for the alias subcommand to the same handler as the other command with arguments. Then also use the AppSettings::Hidden to hide the alias subcommand from the --help message. Just some thoughts.

@kbknapp
Copy link
Member

kbknapp commented May 8, 2016

I've been putting some thought into this, and finally decided on a route to take.

I'll add an App::alias and App::aliases which function as hidden additional subcommands but dispatch to the aliased subcommand. Therefore you only check existence of the aliased command and not all variants.

@kbknapp
Copy link
Member

kbknapp commented May 10, 2016

Once #502 merges I'll put out v2.5.0 on crates.io which contains this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parsing Area: Parser's logic and needs it changed somehow. S-waiting-on-decision Status: Waiting on a go/no-go before implementing
Projects
None yet
Development

No branches or pull requests

2 participants