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

Enable setting the alias via @command() decorator. #34

Open
x3rAx opened this issue Jun 29, 2017 · 1 comment
Open

Enable setting the alias via @command() decorator. #34

x3rAx opened this issue Jun 29, 2017 · 1 comment

Comments

@x3rAx
Copy link

x3rAx commented Jun 29, 2017

I think it would be nice to be able to set the alias inside the subcommand file using the @command() decorator.

It is currently only possible to defined aliases in the parent command by exporting a SubcommandDefinition array:

import { SubcommandDefinition } from 'clime'

export const subcommands: SubcommandDefinition[] = [
    {
        name: 'my-really-annoying-long-but-descriptive-command',
        alias: 'do-it',
    }
]

This way, I will have to maintain the alias in a separate file from the actual subcommand definition file. And it is very easy to forget changing the command definition in the parent command when for example renaming the subcommand.

In this case one would end up with the new command name (without an alias) and the old one (with alias but not working as it is not defined anymore).

SUBCOMMANDS

  my-really-annoying-long-but-descriptive-command [do-it]
  my-long-but-descriptive-command                         - Isn't that a long command?

When setting the alias in the @command() decorator, this would not happen.

Drawbacks

Using this method, every subcommand has to be loaded when executing a subcommand using its alias because clime does not know which command has the given alias. This might produce some unwanted IO, especially in larger applications with many subcommands. But I don't know if this would really be a problem

Solution 1

This behavior could be configurable while bootstrapping clime:

let cli = new CLI(
    Path.basename(process.argv[1]),  // App name
    Path.join(__dirname, 'commands') // Path to commands
    {
        aliasInSubcommand: false // I would prefer it to be `true` by default
    }
);

Solution 2

Don't allow this at all if there are too may concerns but at least let the developer know that something is wrong. (See #33)

@vilicvane
Copy link
Owner

@x3rAx Hi, thanks for your suggestions, though I would prefer the way #33 suggests.

Actually I would agree that it might not be a real performance issue most of the time, not to mention we could have an option for that. However, it's not necessary either as the subcommands entry would be seldom edited. 😂

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

No branches or pull requests

2 participants