I would love to use cobra add to create nested commands, for example:
cobra add db migrate
Cobra would then see that there are multiple arguments, create a directory called db if it doesn't exist and a command file inside of it called migrate.go. It would also create another file either inside of db or at the same directory level called db.go or root.go that will simply create a dbCommand so that nested commands can be added to it. I can submit a PR for this after my existing PR is resolved. Thanks.
@ianwalter I love the idea, please contribute this.
If I can, I'll provide my ideas on what this feature should do/work like.
I think that the syntax should be cobra add db/migrate.
This would create db.go (if needed), db/ (if needed) and db/migrate.go.
It would also add the appropriate AddCommand(addCmd) calls to support the tree structure.
Currently the add command does support the --parent flag which does operate in a similar way, but requires more steps and doesn't put it in a subdirectory.
That sounds good to me. I will work on this. I must have missed --parent. Should I leave it intact? It seems to me that it's functionality would be completely covered by the proposed solution.
Lets leave it for now. It works slightly differently and supports a few use
cases this doesn't.
On Wed, Apr 27, 2016 at 2:30 PM Ian Walter [email protected] wrote:
That sounds good to me. I will work on this. I must have missed --parent.
Should I leave it intact? It seems to me that it's functionality would be
completely covered by the proposed solution.—
You are receiving this because you commented.
Reply to this email directly or view it on GitHub
https://github.com/spf13/cobra/issues/266#issuecomment-215183568
Currently cobra add db/migrate does generate the subdirectory. But the behavior is strange. It generates a var db/migrate = &cobra.Command{}. Should we warn when the command contains "/" first?
I don't think it should warn. I think it should just do the right thing.
Seems like the only bug is how the variable name is created. Should we just
strip the "/"?
On Sun, Sep 4, 2016 at 6:22 AM Wei-Ting Kuo [email protected]
wrote:
Currently cobra add db/migrate does generate the subdirectory. But the
behavior is strange. It generates a var db/migrate = &cobra.Command{}.
Should we warn when the command contains "/" first?—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
https://github.com/spf13/cobra/issues/266#issuecomment-244594810, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAKlZPRgOSRjWlxhioatEActsU7fjCAJks5qmpvdgaJpZM4ICUNR
.
Looks like this bug still exists. I'm happy to work on this.
Please do :)
On Fri, Dec 28, 2018 at 1:31 AM Kasisnu notifications@github.com wrote:
Looks like this bug still exists. I'm happy to work on this.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/spf13/cobra/issues/266#issuecomment-450299660, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAKlZNVE5_7yCjur3t5HqJ8mWxKMVzsIks5u9brAgaJpZM4ICUNR
.
@kasisnu what's the current status?
This issue is being marked as stale due to a long period of inactivity
For me this doesn't create the subdirectory automatically.
Once I create the subdir, it creates a .go file inside it, but as discussed above the file has invalid syntax.
The next problem is that the subdir is considered a separate package (I think?)
Since the parent command, e.g. rootCmd is not exported, it can't be directly referenced.
One more problem is that since the command is now in a "sub-package", that sub-package needs to be explicitly imported somewhere (e.g. main) otherwise it won't even be compiled.
@spf13 Should we make the parent command public? Add a public function? Something else?
@joshuabezaleel I think this issue is a duplicate right?
https://github.com/spf13/cobra/issues/1059
@geniass Yes, I think these 2 issues convey the same problem statement.
I saw that there is a PR submitted already by @Wulfheart (?)
Gonna reply later or in a few days.
No worries. Will be happy to help and contribute if I can be of one @Wulfheart :slightly_smiling_face:
Most helpful comment
@kasisnu what's the current status?