cliffy icon indicating copy to clipboard operation
cliffy copied to clipboard

How do I set an alias for the help command?

Open gamecubate opened this issue 4 years ago • 4 comments

... if possible. Thanks!

gamecubate avatar Oct 01 '20 00:10 gamecubate

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.

drew-y avatar Oct 01 '20 17:10 drew-y

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.

gamecubate avatar Oct 01 '20 17:10 gamecubate

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.

drew-y avatar Oct 01 '20 17:10 drew-y

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)

gamecubate avatar Oct 01 '20 17:10 gamecubate