Anup
Anup

Reputation: 1712

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) {}

Upvotes: 1

Views: 328

Answers (1)

jubnzv
jubnzv

Reputation: 1584

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.

Upvotes: 1

Related Questions