Skip to content

Question: how to make flags required #206

@tleyden

Description

@tleyden

I'm defining some flags like this:

    follow_sync_gwCmd.PersistentFlags().String("url", "", "Sync Gateway URL")
    follow_sync_gwCmd.MarkPersistentFlagRequired("url")

and even explicitly calling ParseFlags (out of desperation):

    Run: func(cmd *cobra.Command, args []string) {

        if err := cmd.ParseFlags(args); err != nil {
            log.Printf("err: %v", err)
        }
                ...
    },

and calling:

$ go run main.go follow_sync_gw

with no --url flag, but cobra isn't throwing errors.

I was expecting that if I set MarkPersistentFlagRequired but failed to pass the flag on the command line then the command would fail with an error and a usage example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions