Skip to content

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

@x3rAx

Description

@x3rAx

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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions