Esempio n. 1
0
func ExampleVarOpt() {

	app := cli.App("var", "Var opt example")

	// Declare a variable of your type
	verbosity := Counter(0)
	// Call one of the Var methods (arg, opt, ...) to declare your custom type
	app.VarOpt("v", &verbosity, "verbosity level")

	app.Action = func() {
		// The variable will be populated after the app is ran
		fmt.Print(verbosity)
	}

	app.Run([]string{"app", "-vvvvv"})
	// Output: 5
}
Esempio n. 2
0
func ExampleVarArg() {

	app := cli.App("var", "Var arg example")

	// Declare a variable of your type
	duration := Duration(0)
	// Call one of the Var methods (arg, opt, ...) to declare your custom type
	app.VarArg("DURATION", &duration, "")

	app.Action = func() {
		// The variable will be populated after the app is ran
		fmt.Print(time.Duration(duration))
	}

	app.Run([]string{"cp", "1h31m42s"})
	// Output: 1h31m42s
}