-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbacb13
commit 1f3d7ee
Showing
1 changed file
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,71 @@ | ||
[](https://github.com/unsafe-risk/broccoli/blob/main/LICENSE) | ||
[](https://github.com/unsafe-risk/broccoli/actions/workflows/go-test.yml) | ||
[](https://pkg.go.dev/v8.run/go/broccoli) | ||
|
||
# broccoli | ||
Broccoli: CLI | ||
|
||
Broccoli: [CLI](https://en.wikipedia.org/wiki/Command-line_interface) Package for Go | ||
|
||
## Usage | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"v8.run/go/broccoli" | ||
) | ||
|
||
type Config struct { | ||
_ struct{} `version:"0.0.1" command:"hello" about:"Test App"` | ||
Name string `flag:"name" alias:"n" required:"true" about:"Your name"` | ||
|
||
Sub *SubCommand `subcommand:"sub"` | ||
} | ||
|
||
type SubCommand struct { | ||
_ struct{} `command:"sub" longabout:"Test Sub Command"` | ||
Name string `flag:"name" alias:"n" required:"true" about:"Your name"` | ||
} | ||
|
||
func main() { | ||
var cfg Config | ||
_ = broccoli.BindOSArgs(&cfg) | ||
|
||
if cfg.Sub != nil { | ||
fmt.Printf("Hello %s from sub command\n", cfg.Sub.Name) | ||
return | ||
} | ||
|
||
fmt.Printf("Hello %s from main command\n", cfg.Name) | ||
} | ||
``` | ||
|
||
``` | ||
$ hello --help | ||
hello 0.0.1 | ||
Test App | ||
Usage: | ||
hello <COMMAND> [OPTIONS] --name <NAME> [ARGUEMENTS] | ||
Options: | ||
-n, --name Your name (required) | ||
-h, --help Print this help message and exit | ||
Commands: | ||
sub Test Sub Command | ||
$ hello --name World | ||
Hello World from main command | ||
$ hello sub --name World | ||
Hello World from sub command | ||
``` | ||
|
||
## Installation | ||
|
||
```bash | ||
go get -u v8.run/go/broccoli | ||
``` |