Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joeychilson/simplecli
A simple CLI library for Go.
https://github.com/joeychilson/simplecli
cli command-line go golang
Last synced: 1 day ago
JSON representation
A simple CLI library for Go.
- Host: GitHub
- URL: https://github.com/joeychilson/simplecli
- Owner: joeychilson
- License: mit
- Created: 2023-03-16T11:38:12.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-03-16T11:53:57.000Z (over 1 year ago)
- Last Synced: 2024-06-19T13:43:47.453Z (5 months ago)
- Topics: cli, command-line, go, golang
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simplecli
A simple CLI library for Go.
## Installation
```bash
go get github.com/joeychilson/simplecli
```## Example
```go
package mainimport (
"context"
"flag"
"fmt"
"os""github.com/joeychilson/simplecli"
)func main() {
var name stringfs := flag.NewFlagSet("hellocmd", flag.ExitOnError)
fs.StringVar(&name, "name", "world", "name to say hello to")helloCmd := &simplecli.Command{
Name: "hello",
Aliases: []string{"hi", "hey"},
Usage: "say hello to someone",
FlagSet: fs,
Exec: func(ctx context.Context, args []string) error {
fmt.Printf("Hello %s!\n", name)
return nil
},
}rootCmd := &simplecli.Command{
Name: "mycli",
Aliases: []string{"my"},
SubCommands: []*simplecli.Command{helloCmd},
}if err := rootCmd.ParseAndExec(context.Background(), os.Args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}
```