Search code examples
gogo-cobra

How to set command name prefixed with -- in cobra


I want to create a command with name --list, but if I set --list as Use property of cobra.Command it does not works. Like bellow code does not works. Any help?

    list := &cobra.Command{
    Use:   "--list",
    Short: "Lists all data",
    Run: func(*cobra.Command, []string) {}

Solution

  • You can't create a command with a name starting with - or --, because in cobra these are flags. See the corresponding source code in the library, which removes them when parsing the command.