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

How do I set an alias for the help command? #12

Open
gamecubate opened this issue Oct 1, 2020 · 4 comments
Open

How do I set an alias for the help command? #12

gamecubate opened this issue Oct 1, 2020 · 4 comments

Comments

@gamecubate
Copy link

... if possible. Thanks!

@drew-y
Copy link
Owner

drew-y commented Oct 1, 2020

I just published cliffy version 2.4.0 which adds a cli.showHelp() method. You could alias the main help menu like this:

import { CLI } from "cliffy";

// Alias help to h
cli.addCommand("h", async () => {
    cli.showHelp();
});

Although this does not alias the help command for subcommands. Only the main command.

Adding an alias for something like this:

help mycommand

Is not currently possible. But It wouldn't be too much work to make that possible as well. So let me know if it's something you need.

@gamecubate
Copy link
Author

gamecubate commented Oct 1, 2020

Hi @drew-y, and thanks!

I thought of adding a cli.addCommandAlias(<command id>, <alias>) method to the class and submitting a PR. But, not having had the time to look into your code, I had no idea of complexity.

Sample use: myCLI.addCommandAlias("help","h") .

I assume I would have to tap into CLI's (input) command interpreter (assuming there is one). Will look it up later and submit if that's ok with you.

@drew-y
Copy link
Owner

drew-y commented Oct 1, 2020

That isn't a bad idea. But you'd have to add special logic for the help command specifically.

Internally, the executeCommand method checks to see if the first argument is help. So all you need to do is add additional logic that checks for help aliases. Which wouldn't be too difficult at all.

@gamecubate
Copy link
Author

gamecubate commented Oct 1, 2020

Oh I see that you had already implemented aliases, although I didn't see any of that in the README. Will have to play some more.

EDIT
Oops. Looks like aliases in your code are not those I had in mind. Perhaps will tap into the addCommand method by adding an optional "shorthand" property and see where that takes me (adding a this.shorthands[] array to CLI as well)

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

No branches or pull requests

2 participants