Skip to content
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

Adding commands with dashes("-") in the name generates bad code #269

Closed
dcu opened this issue Apr 14, 2016 · 8 comments
Closed

Adding commands with dashes("-") in the name generates bad code #269

dcu opened this issue Apr 14, 2016 · 8 comments
Assignees
Labels
area/cobra-command Core `cobra.Command` implementations kind/bug A bug in cobra; unintended behavior

Comments

@dcu
Copy link

dcu commented Apr 14, 2016

For example when running cobra add-user the name of the command in the code is add-userCmd which is wrong.

@SystemZ
Copy link

SystemZ commented Apr 24, 2016

Exact issue for me.
I need - because external app calls appname backup-end and I can't change that

@spf13
Copy link
Owner

spf13 commented Apr 27, 2016

Just clarifying, this is only an issue with the Cobra generation tool, not with the library itself, correct?

@SystemZ
Copy link

SystemZ commented Apr 27, 2016

No idea, I'm still learning Go :)

@dcu
Copy link
Author

dcu commented Apr 27, 2016

@spf13 yes I think it's just generation.

@jdub
Copy link

jdub commented Apr 30, 2016

Yes, just in generation:

$ cobra add get-metadata
$ go run main.go
# github.com/jdub/cfn-init-tools/cmd
cmd\get-metadata.go:30: syntax error: unexpected -
cmd\get-metadata.go:39: syntax error: unexpected {, expecting name
cmd\get-metadata.go:41: syntax error: unexpected fmt, expecting (
cmd\get-metadata.go:41: method has multiple receivers
cmd\get-metadata.go:42: syntax error: non-declaration statement outside function body

Lines 30 and 46:

var get-metadataCmd = &cobra.Command{
...
RootCmd.AddCommand(get-metadataCmd)

Probably makes sense to automagically camel case dashed (or underscored, ew, why) commands, e.g. getMetadataCmd.

@nouney nouney mentioned this issue Nov 7, 2016
@n10v n10v added area/cobra-command Core `cobra.Command` implementations kind/bug A bug in cobra; unintended behavior labels Apr 21, 2017
n10v added a commit to n10v/cobra that referenced this issue May 1, 2017
@n10v n10v mentioned this issue May 1, 2017
3 tasks
n10v added a commit that referenced this issue May 1, 2017
n10v added a commit to n10v/cobra that referenced this issue May 2, 2017
@n10v n10v closed this as completed in #428 May 5, 2017
n10v added a commit that referenced this issue May 5, 2017
@lzhecheng
Copy link

It seems that, dash in command name will be camel cased now. What should I do if I want to have a command name with dash ?

@lzhecheng
Copy link

It seems that, dash in command name will be camel cased now. What should I do if I want to have a command name with dash ?

I got it. Just change "Use" in cobra.Command {}

@jsuar
Copy link

jsuar commented Jan 5, 2020

@lzhecheng More specifically, the alias field can be used. I was wondering the same.

var foobarCmd = &cobra.Command{
	Use:     "foobar",
	Aliases: []string{"foo-bar", "FooBar"},
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cobra-command Core `cobra.Command` implementations kind/bug A bug in cobra; unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants