From 1f3d7ee4b82fabd3277a2e0c5bdb087bdb00f383 Mon Sep 17 00:00:00 2001 From: lemon-mint Date: Sat, 20 Aug 2022 16:10:36 +0900 Subject: [PATCH] Update README --- README.md | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6364714..fa81f58 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,71 @@ +[![GitHub](https://img.shields.io/github/license/unsafe-risk/broccoli?style=for-the-badge)](https://github.com/unsafe-risk/broccoli/blob/main/LICENSE) +[![GitHub Workflow Status (event)](https://img.shields.io/github/workflow/status/unsafe-risk/broccoli/go-test?event=push&style=for-the-badge)](https://github.com/unsafe-risk/broccoli/actions/workflows/go-test.yml) +[![Go Reference](https://img.shields.io/badge/go-reference-%23007d9c?style=for-the-badge&logo=go)](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 [OPTIONS] --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 +```