Created
April 26, 2016 04:42
-
-
Save mkideal/cc324e88238a60714b9b9d4302c6ed08 to your computer and use it in GitHub Desktop.
simple demo for building command line app with golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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