https://github.com/linuxsuren/cobra-extension
This is the extension of cobra which is a Commander for modern Go CLI interactions
https://github.com/linuxsuren/cobra-extension
cli cobra cobra-extension hacktoberfest
Last synced: 10 months ago
JSON representation
This is the extension of cobra which is a Commander for modern Go CLI interactions
- Host: GitHub
- URL: https://github.com/linuxsuren/cobra-extension
- Owner: LinuxSuRen
- License: mit
- Created: 2020-12-04T00:24:35.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-02T19:57:32.000Z (about 3 years ago)
- Last Synced: 2025-04-30T20:07:43.639Z (10 months ago)
- Topics: cli, cobra, cobra-extension, hacktoberfest
- Language: Go
- Homepage:
- Size: 119 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://goreportcard.com/report/linuxsuren/cobra-extension)
[](https://godoc.org/github.com/linuxsuren/cobra-extension)
[](https://github.com/linuxsuren/cobra-extension/graphs/contributors)
[](https://github.com/linuxsuren/cobra-extension/releases/latest)

[](http://hits.dwyl.com/linuxsuren/cobra-extension)
This project aims to provide an easy way to let you writing a plugin for your CLI project. And it based on [cobra](https://github.com/spf13/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:
```go
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())
}
```