checkFlagExistsInCmd ensures that the command contains the flag that is passed from the test suite. The test suite should always be the source of truth with regards to which flags must exists in the command.
(cmd *cobra.Command, flag string)
| 68 | // passed from the test suite. The test suite should always be the source of |
| 69 | // truth with regards to which flags must exists in the command. |
| 70 | func checkFlagExistsInCmd(cmd *cobra.Command, flag string) error { |
| 71 | if cmdFlag := cmd.Flag(flag); cmdFlag == nil { |
| 72 | return fmt.Errorf("Unknown flag `%s` for `%s %s`", |
| 73 | flag, cmd.Parent().Name(), cmd.Name()) |
| 74 | } |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | // resetFlagsFromMap resets each key or flag name from a flags map to it's |
| 79 | // default value. This can be used for test teardown to ensure that the used |