This project aims to provide an easy way to let you writing a plugin for your CLI project. And it based on cobra.
go get github.com/linuxsuren/cobra-extension
You can add some tests for the flags quickly, for instance:
func TestFlagsValidation_Valid(t *testing.T) {
boolFlag := true
emptyFlag := true
cmd := cobra.Command{}
cmd.Flags().BoolVarP(&boolFlag, "test", "t", false, "usage test")
cmd.Flags().BoolVarP(&emptyFlag, "empty", "", false, "")
flags := FlagsValidation{{
Name: "test",
Shorthand: "t",
}, {
Name: "empty",
UsageIsEmpty: true,
}}
flags.Valid(t, cmd.Flags())
}