rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[rush] Support subcommands in command-line.json

Open atsixian opened this issue 3 years ago • 2 comments

Summary

I added a custom command into command-line.json, and I'm wondering if it's possible to add subcommands to my command because it's getting complicated. Example:

> rush my-command subcommand --options

The schema(https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json) only allows adding parameters. And I found a closed PR https://github.com/microsoft/rushstack/pull/1777 related to subcommands. Is there any plan to support this?

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/rush globally installed version? 5.47.0
rushVersion from rush.json? 5.67.0
useWorkspaces from rush.json? true
Operating system? Mac
Would you consider contributing a PR? Yes
Node.js version (node -v)? 12.21.0

atsixian avatar Apr 28 '22 06:04 atsixian

The @rushstack/ts-command-line library doesn't currently support this concept, so this capability would need to be added there. The linked PR is a different concept altogether, namely running other code in addition to the specified command (it isn't a change to the command line parsing).

This would need design. @octogonz

dmichon-msft avatar May 02 '22 18:05 dmichon-msft

There are two proposed features that might solve this:

  • The CommandLineRemainder (issue #2499) feature would allow arbitrary CLI parameters to be passed along to your script without any validation, help docs, or shell tab-completion. This is useful when another tool is being wrapped, but not the best practice or recommendation, because we want commands to have validation.

  • We've also been working on a revamp of ts-command-line where JSON files (or data structures) are the primary mechanism for defining the CLI. This allows the CLI spec to be completely decoupled from the implementation, which helps with performance and other problems like localization. It would also provide a convenient way for a front-end like Rush to wrap a CLI that is defined externally to Rush, so it is similar to CommandLineRemainder but would provide validation, docs, tab-completion, etc. I started a prototype branch but got busy with other things, however it seems like a good direction longer term.

At the same time, I will note that the philosophy of ts-command-line is to avoid complex CLI syntaxes. Adding more parameters and alternatives and subcommands produces a user interface that is difficult to document well, and difficult for newcomers to learn, particularly if typical usage of your CLI involves specifying lots of options. Instead we recommend to keep the CLI simple and move all those advanced options into a config file, which can have code comments, JSON schema IntelliSense, and a more readable Git history. This philosophy is partly why we haven't given higher priority to some of the feature requests for ts-command-line.

octogonz avatar Jun 24 '22 23:06 octogonz