Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/orisano/subflag
subflag is subcommand library for flag package
https://github.com/orisano/subflag
Last synced: 24 days ago
JSON representation
subflag is subcommand library for flag package
- Host: GitHub
- URL: https://github.com/orisano/subflag
- Owner: orisano
- License: mit
- Created: 2018-09-13T15:02:17.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-08T20:04:07.000Z (almost 3 years ago)
- Last Synced: 2024-10-04T17:51:13.071Z (about 1 month ago)
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# subflag
subflag is a subcommand library for `flag` package.## Installation
```bash
go get github.com/orisano/subflag
```## How to use
```go
package mainimport (
"flag"
"fmt"
"log"
"os"
"github.com/orisano/subflag"
)func main() {
if err := subflag.SubCommand(os.Args[1:], []subflag.Command{&EchoCommand{}}); err != nil {
log.Fatal(err)
}
}type EchoCommand struct {
text string
}func (c *EchoCommand) FlagSet() *flag.FlagSet {
flagSet := flag.NewFlagSet("echo", flag.ExitOnError)
flagSet.StringVar(&c.text, "t", c.text, "echo text (required)")
return flagSet
}func (c *EchoCommand) Run(args []string) error {
if len(c.text) == 0 {
return flag.ErrHelp
}
fmt.Println(c.text)
return nil
}
```## Author
Nao Yonashiro (@orisano)## License
MIT