flag redefined crash

1,019 views
Skip to first unread message

brunetto

unread,
Feb 2, 2014, 8:52:47 AM2/2/14
to golan...@googlegroups.com
Hi all!
I'm using the great Cobra (https://github.com/spf13/cobra) package to implement subcommands in my (little) code.
I have two questions, the first is more Cobra-related (I didn'f find a cobra google group) and the second more general:

First question:
--------------------

* I have (for example) two subcommands A and B and the A subcommand include some functions and the function called by B
* Thus A and B need to share some flags
* I can't attach the same flags to two different subcommands otherwise my program will crash with  `panic: <B> flag redefined: <flag name>

I can agree that using the same flag with different meanings in different context can be confusing, but the same flag with the same meaning
shouldn't be a problem. Moreover, now I have to put the flags as persistent and attach them to the root command and I
don't think this is a great solution because I am linking flags with a command (the root one) that doesn't need them.

Is there a better solution?

Second question:
-------------------------

Why is not possible to check for redefined flags at compile time (given that they are written in the source) instead of crash 
at run time?

thanks a lot

brunetto

Herbert Fischer

unread,
Feb 2, 2014, 10:54:02 AM2/2/14
to brunetto, golang-nuts
Hi brunetto,

You can send an email directly to the cobra author: https://github.com/spf13

cheers


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

DisposaBoy

unread,
Feb 3, 2014, 2:26:54 AM2/3/14
to golan...@googlegroups.com
How is that possible?

brunetto

unread,
Feb 3, 2014, 6:36:54 PM2/3/14
to golan...@googlegroups.com
On Monday, 3 February 2014 08:26:54 UTC+1, DisposaBoy wrote:
How is that possible?

It seems that I made a mistake and if I separate the flags in different subcommands it works!
I'm sorry.

However I'm still asking myself if it is possible to catch flag errors at compile time.

brunetto


Reply all
Reply to author
Forward
0 new messages