Skip to content

Show error/warning when SubcommandDefinition contains non-existing commands #33

Description

@x3rAx

When defining subcommand properties like alias or brief in the parent commands subcommands export, there is no error shown, when a subcommand does not exist:

src/
+-- app.ts
+-- commands/
|   +-- default.ts
|   +-- my-command.ts
// src/commands/default.ts

import { SubcommandDefinition } from 'clime'

export const subcommands: SubcommandDefinition[] = [
    {
        name: 'my-cool-command',
        brief: "Isn't it cool?",
    }
]
$ node bin/app
  USAGE

    app <subcommand>

  SUBCOMMANDS

    my-cool-command        - Isn't it cool?
    my-command             - It's definitely cool!.

$ node bin/app my-cool-command
ERR Unknown subcommand "my-cool-command".

  USAGE

    app <subcommand>

  SUBCOMMANDS

    my-cool-command        - Isn't it cool?
    my-command             - It's definitely cool!.

As you can see, there is no such command like my-cool-command but it is displayed because it is defined in default.ts.

My suggestion is to test if the command exists (or at least if one of the files my-cool-command.js or my-cool-command/default.js exist) and to present the user with an error or at least a warning when it does not.

Example:

$ node bin/app
  USAGE

    app <subcommand>

  SUBCOMMANDS

    my-command             - It's definitely cool!.

WARN Subcommand 'my-cool-command' is defined but does not exist!

Note that the missing subcommand would not be listed as subcommand and a warning would be displayed below the output.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions