Exemple #1
0
func main() {
	prog := argparse.New()
	prog.Description("app", "sample app").Version("0.0.0")
	prog.Epilog("this is the end!")
	prog.Command("s", "start", "start application", func(a argparse.Args) {
		fmt.Println("application started")
	}).Command("x", "stop", "stop application", func(a argparse.Args) {
		fmt.Println("application stopped")
	}).Command("f", "flags", "process flags", func(a argparse.Args) {
		for key, value := range a.ArgMap {
			fmt.Println(key, value)
		}
	})
	prog.Parse()
}
Exemple #2
0
func main() {
	program := argparse.New()
	program.Description(pushdName, pushdDecription)
	program.Version(pushdVersion)
	program.Epilog("See " + pushdHomepage + " for feature requests and bug reports")
	program.Command("s", "start", "start daemon", func(a argparse.Args) {
		out.Info("starting daemon")
		d := new(Daemon)
		d.Port = a.AsString("port", "p")
		d.Start()
	})
	program.Command("x", "stop", "stop daemon", func(a argparse.Args) {
		out.Info("stopping daemon")
		res, err := StopDaemon(a.AsString("port", "p"))
		if err != nil {
			out.Error("errored: %s", err)
			return
		}
		out.Info("response: %s", res)
	})
	program.Command("?", "status", "check status", func(a argparse.Args) {
		out.Info("checking daemon status")
		res, err := CheckDaemonStatus(a.AsString("port", "p"))
		if err != nil {
			out.Error("errored: %s", err)
			return
		}
		out.Info("response: %s", res)
	})
	program.Command("n", "notify", "push notification", func(a argparse.Args) {
		out.Info("sending notification")
		res, err := SendNotification(a.AsString("port", "p"), a.AsString("message", "m"))
		if err != nil {
			out.Error("errored: %s", err)
			return
		}
		out.Info("response: %s", res)
	})
	program.Parse()
}