There are a handful of powerful go CLI libraries available (spf13/cobra, urfave/cli). However sometimes an integrated shell interface is a great and useful extension for the actual application. This library offers a simple API to create powerful CLI applications and automatically starts an integrated interactive shell, if the application is started without any command arguments.
Hint: The API might change slightly, until a first 1.0 release is published.
Create a grumble APP.
var app = grumble.New(&grumble.Config{
Name: "app",
Description: "short app description",
Flags: func(f *grumble.Flags) {
f.String("d", "directory", "DEFAULT", "set an alternative directory path")
f.Bool("v", "verbose", false, "enable verbose mode")
},
})
Register a top-level command. Note: Sub commands are also supported...
app.AddCommand(&grumble.Command{
Name: "daemon",
Help: "run the daemon",
Aliases: []string{"run"},
Usage: "daemon [OPTIONS]",
AllowArgs: true,
Flags: func(f *grumble.Flags) {
f.Duration("t", "timeout", time.Second, "timeout duration")
},
Run: func(c *grumble.Context) error {
c.App.Println("timeout:", c.Flags.Duration("timeout"))
c.App.Println("directory:", c.Flags.String("directory"))
c.App.Println("verbose:", c.Flags.Bool("verbose"))
// Handle args.
c.App.Println("args:")
c.App.Println(strings.Join(c.Args, "\n"))
return nil
},
})
Run the application.
err := app.Run()
Or use the builtin grumble.Main function to handle errors automatically.
func main() {
grumble.Main(app)
}
Builtin support for multiple lines.
>>> This is \
... a multi line \
... command
Check out the sample directory for some detailed examples.
The grml project uses grumble.
This project is based on ideas from the great ishell library.
MIT