-
Notifications
You must be signed in to change notification settings - Fork 120
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
About subcommand directory #106
Comments
(Copying myself from spf13/cobra#1059 (comment)) Interestingly, the user_guide.md displays how to organise subcomands in folders but does or could cobra-cli support it? |
The current behavior is good, it is useful for the common case of single package command. I think the missing part is to support also the hierarchical layout when initializing a project or adding a command. I can think of 2 ways to solve this: add flagAdding a child command as a package:
Will create:
Adding a sub command of foo:
Will create:
Adding a sub package for foo:
Generator optionAdd an option the the .cobra.yaml to use single package or multi-package layout. This will make it easier to have consistent initialization in the entire project. Example yaml for single package (default):
With this child commands are created in the same package as root and add the child command to the root command in the child init(). Example yaml for multi-package layout (new):
With this child command is created in a new package and parent init() is changed to add the child command. This does not solve he issue of adding a leaf command in a sub package, in this case we most likely want to keep the leaf file in the parent package. |
Yes, I think so. Yesterday I found this video where the author presents a simple semi-manual workaround how to use Cobra CLI and maintain folder-based structure of commands. Here is the specific moment linked How to write beautiful Golang CLI |
This is transfer of @fanux's spf13/cobra#1059 as suggested there by @johnSchnake
cobra generates subcommand
user
in the same dir of its parent dir, it not very nice.If I add a command
user
this user command is notcreate
subcommand:So I think,
create
subcommand in a sub dir is better, like this:This will not conflict
The text was updated successfully, but these errors were encountered: