Documentation ¶
Index ¶
- func CobraFlagPromptPreRunE(cmd *cobra.Command, args []string, stdIn io.Reader, stdOut io.Writer) error
- func MarkFlagRequired(cmd *cobra.Command, name string) error
- func MarkPersistentFlagRequired(cmd *cobra.Command, name string) error
- func PromptForFlag(flag *pflag.Flag, stdIn io.Reader, stdOut io.Writer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CobraFlagPromptPreRunE ¶
func CobraFlagPromptPreRunE(cmd *cobra.Command, args []string, stdIn io.Reader, stdOut io.Writer) error
CobraFlagPromptPreRunE is the cobraFlagPrompt PreRunE code which will prompt the user to enter information for missing flags. cobraFlagPrompt makes an effort to call this function for you. Most developers will not need to call it manually. However, if you do find yourself needing to trigger this function manually, make sure you call it exactly once per cmd *cobra.Command.
Inputs: cmd where we can find the flags; args from the program; os.StdOut (pass this in to help with testing)
If there are no cobraFlagPrompt required flags registered at the cmd, this func does nothing.
Developer note: This code is automatically attached to PreRunE when you call MarkFlagRequired or MarkPersistentFlagRequired BUT if you set PreRunE *after* calling MarkFlagRequired or MarkPersistentFlagRequired, that will overwrite this PreRunE. In that scenario, you will need to manually call CobraFlagPromptPreRunE *at the very end of your PreRunE*. Because Cobra prefers PreRunE over PreRun (it's an if / else if), if you set your own PreRun after calling MarkFlagRequired or MarkPersistentFlagRequired then that PreRun will be ignored (unless you also cleared out PreRunE).
func MarkFlagRequired ¶
MarkFlagRequired causes the command to prompt the user if this flag is not provided as a command line argument.
func PromptForFlag ¶
PromptForFlag prompts the user to enter a value for pflag. It can handle any type of flag supported by cobra.
The value received from the user is stored in the same way cobra stores it and is retrievable in the same way.
Types ¶
This section is empty.