Skip to content

LinuxSuRen/cobra-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

This is the extension of cobra which is a Commander for modern Go CLI interactions

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published