Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/relastle/colorflag
:lollipop: Colored help (usage) for flag (standard library)
https://github.com/relastle/colorflag
cli go
Last synced: about 2 months ago
JSON representation
:lollipop: Colored help (usage) for flag (standard library)
- Host: GitHub
- URL: https://github.com/relastle/colorflag
- Owner: relastle
- License: mit
- Created: 2019-09-25T09:22:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-26T07:16:41.000Z (over 5 years ago)
- Last Synced: 2024-06-19T05:45:31.996Z (7 months ago)
- Topics: cli, go
- Language: Go
- Homepage:
- Size: 1.71 MB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# colorflag
colorflag provides colorized help for CLI applications using Go's `flag` standard library
## Installation
```zsh
go get github.com/relastle/colorflag
```## Example
#### Sample code
```go
package mainimport (
"flag""github.com/relastle/colorflag"
)func main() {
// main command
flag.String("main-opt1-string", "", "Description of `quoted target`")
flag.Int("main-opt2-integer", 0, "Description of integer option")// sub command 1
sub1FlagSet := flag.NewFlagSet("sub1", flag.ExitOnError)
sub1FlagSet.String("sub1-option-string", "default string value", "Description of string option of sub command 1")
sub1FlagSet.Int("sub1-option-integer", 2, "Description of integer option for sub command")
sub1FlagSet.Bool("sub1-flag-bool", false, "Description of flag for sub command")// sub command 2
sub2FlagSet := flag.NewFlagSet("sub2", flag.ExitOnError)
sub2FlagSet.String("sub2-option-string", "", "Description of string option of sub command 2")// Optional
colorflag.Indent = 4 // default is 2
colorflag.ExpandsSubCommand = true // default is true
colorflag.TitleColor = "green" // default is yellow
colorflag.FlagColor = "cyan" // default is green// Parse (and return selected sub command name)
subCommand := colorflag.Parse([]*flag.FlagSet{
sub1FlagSet,
sub2FlagSet,
})switch subCommand {
case "sub1":
// Handle sub1 sub-command
case "sub2":
// Handle sub2 sub-command
}
}
```#### Help output
![](./_example/figures/sub-expand-example.png)
# [License](LICENSE)
The MIT License (MIT)