Skip to content

Latest commit

 

History

History
35 lines (28 loc) · 1.48 KB

README.md

File metadata and controls

35 lines (28 loc) · 1.48 KB

Contributors GitHub release GitHub code size in bytes HitCount

This project aims to provide an easy way to let you writing a plugin for your CLI project. And it based on cobra.

Get started

go get github.com/linuxsuren/cobra-extension

Friendly to the flags test

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