https://github.com/gowww/cli
🖥 Wrap the standard flag package for a cleaner CLI
https://github.com/gowww/cli
cli command command-line console interface terminal tool
Last synced: 4 months ago
JSON representation
🖥 Wrap the standard flag package for a cleaner CLI
- Host: GitHub
- URL: https://github.com/gowww/cli
- Owner: gowww
- License: mit
- Created: 2017-07-11T21:37:04.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-09-15T10:55:24.000Z (almost 6 years ago)
- Last Synced: 2025-08-14T06:02:10.692Z (10 months ago)
- Topics: cli, command, command-line, console, interface, terminal, tool
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [](https://github.com/gowww) cli [](https://godoc.org/github.com/gowww/cli) [](https://travis-ci.org/gowww/cli) [](https://coveralls.io/github/gowww/cli?branch=master) [](https://goreportcard.com/report/github.com/gowww/cli) 
Package [cli](https://godoc.org/github.com/gowww/cli) wraps the standard [flag](https://golang.org/pkg/flag/) package for a cleaner command line interface.
## Installing
1. Get package:
```Shell
go get -u github.com/gowww/cli
```
2. Import it in your code:
```Go
import "github.com/gowww/cli"
```
## Usage
Henceforth, by "command" we mean "subcommand" (like the `build` part in `go build`)…
The order in which you define commands and flags is important!
When you define a main flag, it will be added to the top-level flag set but also to all commands already defined.
Obviously, each command can also define its own flags.
For the sake of clarity for the developer and ease of use for the final user, the usage pattern is simple and always the same : `program [command] [flags]`. No flags before command, and no commands of commands.
### Example
```Go
package main
import "github.com/gowww/cli"
var (
flagForMain string // Flag "-m"
flagForCommand string // Flag "-c"
flagForAll string // Flag "-a"
)
func main() {
cli.SetUsageText("Command line interface example.")
cli.String(&flagForMain, "m", "", "Example flag for main function.")
cli.Command("command", command, "Example command.").
String(&flagForCommand, "c", "", `Example flag for this command only.`)
cli.String(&flagForAll, "a", "", "Example flag for main function and all commands defined previously.")
cli.Parse()
}
func command() {
// Do the command job.
}
```
#### Usage output
##### For `example -help`
```
Command line interface example.
Usage:
example [command] [flags]
Commands:
command Example command.
Flags:
-a Example flag for main function and all commands defined previously.
-m Example flag for main function.
```
##### For `example command -help`
```
Example command.
Usage:
example command [flags]
Flags:
-a Example flag for main function and all commands defined previously.
-c Example flag for this command only.
```