package main import ( "fmt" "github.com/smira/commander" ) func main() { c := commander.Command{ UsageLine: "hello", Short: "prints hello world", Run: func(cmd *commander.Command, args []string) error { fmt.Println("Hello, world!") return nil }, } c.Dispatch(nil) }
package main import ( "fmt" "github.com/smira/commander" ) func main() { root := commander.Command{ UsageLine: "myapp", Short: "my awesome app", } greetingCmd := commander.Command{ UsageLine: "greetIn this example, we define a root command named "myapp" with one subcommand named "greet". The "greet" command takes an argument for a name and prints out a greeting. We use the `Subcommands` field to specify the subcommands for the root command. Overall, the Commander package allows you to easily define and execute commands in your Go application. It is a great choice for creating your own command line interface.", Short: "greets someone by name", Run: func(cmd *commander.Command, args []string) error { fmt.Printf("Hello, %s!\n", args[0]) return nil }, } root.Subcommands = []commander.Command{greetingCmd} root.Dispatch(nil) }