GitHub - SuperPaintman/nice: Highly customizable and lightweight Go CLI app fram...
source link: https://github.com/SuperPaintman/nice
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Nice
Nice is a highly customizable and lightweight framework for crafting CLI apps.
Nice respects idiomatic Go code and focuses to be clear, efficient and easy to write and maintain.
You can use it as a full-featured non-opinionated framework or use any nice packages as stand-alone libraries.
I hope you'll enjoy your nice CLI app!
Hello, Nice!
Let's start with your first Nice CLI app.
First, install the framework:
$ go get github.com/SuperPaintman/nice/cli
Then put this code into a file (hello.go
for example):
package main import ( "log" "github.com/SuperPaintman/nice/cli" ) func main() { app := cli.App{ Name: "hello", Usage: cli.Usage("Print a friendly greeting"), Action: cli.ActionFunc(func(ctx cli.Context) cli.ActionRunner { name := cli.StringArg(ctx, "name", cli.Usage("Who we say hello to"), cli.Optional, ) *name = "Nice" // Default value. return func(ctx cli.Context) error { ctx.Printf("Hello, %s!\n", *name) return nil } }), CommandFlags: []cli.CommandFlag{ cli.HelpCommandFlag(), cli.VersionCommandFlag("0.0.0"), }, } if err := app.Run(); err != nil { log.Fatal(err) } }
Now you can run it!
$ go run . world
Or print the help for your app:
$ go run . -h
Tests
$ go test ./... -test.short
$ go test ./... -bench=. -benchmem -run='^Benckmark'
Similar projects
License
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK