-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Registering git style subcommands leveraging standalone executable files #1417
Comments
I am not seeing the problem on the It works the way I expect when I try: $ ./cli.js
# displays help from cli.js, including command dotnet
$ ./cli.js dotnet
# displays dotnet help from cli-dotnet.js, including command version
$ ./cli.js dotnet version
# runs cli-dotnet-version.js |
@shadowspawn Correct - the |
Ah thanks, I am understanding question better on second read. I'll try explaining, and may lead to more questions about how things could be arranged. With stand-alone executables, you can't wire it all up at the top level. There isn't a full "command" added for a stand-alone executable, just a placeholder that there is an external command. In particular, note:
So on your issue branch,
|
Gotcha. That's what I was thinking based on the docs and from playing around with a few different configurations of the functions available. Not sure if this is something that's on the roadmap, but I would love to see it. My team has invested in a custom CLI project to ease and automate our day-to-day engineering and devops, and it has grown significantly in the last year. (Just completed a TypeScript port of ~130 files) We've gotten by so far by using standalone executable files that use multiple options to wire up logic that is extracted out into shared modules, but I think we've hit a point with some of the commands that it makes sense to pull out another level of commands to group the operations by. I can move forward with registering the subcommands in the standalone files for now - thanks for taking a look and clarifying. Feel free to close this out unless you'd like to keep it around as a feature request. Cheers! 🍻 |
In your example, will the intermediate command (I am wondering whether the setup of |
Hmmm... well, in our actual project, I think we might need both. For example, we currently have a What spawned this issue was moreso for our We have all of that in a flat Apologies for the long-winded response - another reason we would like to keep registering the commands the same way (externally) is to support a 'plugin' structure - we built out an abstraction that allows consumers to pull in all (or some) of our base commands and add custom commands for their own project-specific needs, which hinges on referencing the executable file in the |
Interesting, thanks. Nice to see how easy it is to scan a directory with files for subcommands. This may not be relevant to your setup, but the hoisting I had in mind (in const dotnet = program
.command("dotnet")
.description("Parent command housing operations around the dotnet cli");
dotnet.command("version", "Displays dotnet installation info", {
executableFile: "cli-dotnet-version.js",
}); (Requires Commander v6.1 or higher which fixes a bug calling external subcommands from a nested command, your repo has Commander v6.0.0.) |
I see @shadowspawn. By registering the command that way, it delegates to the |
An answer was provided, and no further activity in a month. Closing this as resolved. Feel free to open a new issue if it comes up again, with new information and renewed interest. |
Context:
I am unsure if there is something incorrect with my setup/proposed use-case, or if this is a feature that isn't supported yet by the API. May be related to #714. I am working off of version 6.0.0.
Use-case:
I would like to be able to register commands (parent and nested) that exist as standalone executable files from the entrypoint or 'top-level' command file.
Problem:
The
command()
overload that takes the{ executableFile?: string }
object only exists on thecommander.CommanderStatic
instance and not theaddCommand()
function which is used to add prepared subcommands.I have an example repository here, which has a workaround solution in the
main
branch (ie, I register the subcommandcli-dotnet-version.js
in the standalone file for the parent,cli-dotnet.js
), whereas in theissue
branch, I would really like to be able to register bothdotnet
and its subcommandversion
incli.js
so I can run./cli.js dotnet version
In the
issue
branch, the output from running the cli has both commands at the entrypoint level andversion
does not get nested underdotnet
:whereas the output from the
main
branch is what I'm looking for:The text was updated successfully, but these errors were encountered: