Skip to content

Instantly share code, notes, and snippets.

@mkideal
Created April 26, 2016 04:42
Show Gist options
  • Save mkideal/cc324e88238a60714b9b9d4302c6ed08 to your computer and use it in GitHub Desktop.
Save mkideal/cc324e88238a60714b9b9d4302c6ed08 to your computer and use it in GitHub Desktop.
simple demo for building command line app with golang
package main
import (
"github.com/mkideal/cli"
)
type argT struct {
Help bool `cli:"h,help" usage:"display help information"`
Name string `cli:"name" usage:"your name" dft:"world"`
Age uint8 `cli:"a,age" usage:"your age" dft:"100"`
}
func main() {
cli.Run(&argT{}, func(ctx *cli.Context) error {
argv := ctx.Argv().(*argT)
if argv.Help {
ctx.String(ctx.Usage())
} else {
ctx.String("Hello, %s! Your age is %d?\n", argv.Name, argv.Age)
}
return nil
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment