Example #1
0
func main() {
	pflag.Usage = func() {
		fmt.Fprintf(os.Stderr, USAGE)
	}

	var output = pflag.StringP("output", "o", ".", "output directory")
	var version = pflag.BoolP("version", "", false, "version")
	pflag.Parse()

	if *version {
		fmt.Println(VERSION)
	} else if pflag.NArg() > 0 {
		genRoutes(pflag.Args(), *output)
	} else {
		routes.PrintTemplatesPath()
		pflag.Usage()
	}
}
Example #2
0
func main() {
	cli.AppHelpTemplate = `{{.Name}} v{{.Version}} - {{.Usage}}

USAGE:
   {{.Name}} {{if .Flags}}[options] {{end}}<template ..>

COMMANDS:
   {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
   {{end}}{{if .Flags}}
GLOBAL OPTIONS:
   {{range .Flags}}{{.}}
   {{end}}{{end}}
`

	app := cli.NewApp()
	app.Name = "freedom-routes"
	app.Version = VERSION
	app.Usage = "generate routes-up.sh and route-down.sh"

	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "output, o",
			Value: ".",
			Usage: "output directory",
		},
	}

	app.Action = func(c *cli.Context) {
		if c.Args().Present() {
			genRoutes(c.Args(), c.String("output"))
		} else {
			cli.ShowAppHelp(c)
			routes.PrintTemplatesPath()
		}
	}

	app.Run(os.Args)
}