dreadl0ck / grumble

A powerful modern CLI and SHELL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Grumble - A powerful modern CLI and SHELL

GoDoc Go Report Card

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.

asciicast

Introduction

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 {
        fmt.Println("timeout:", c.Flags.Duration("timeout"))
        fmt.Println("directory:", c.Flags.String("directory"))
        fmt.Println("verbose:", c.Flags.Bool("verbose"))

        // Handle args.
        fmt.Println("args:")
        fmt.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)
}

Shell Multiline Input

Builtin support for multiple lines.

>>> This is \
... a multi line \
... command

Samples

Check out the sample directory for some detailed examples.

The grml project uses grumble.

Additional Useful Packages

Credits

This project is based on ideas from the great ishell library.

License

MIT

About

A powerful modern CLI and SHELL

License:MIT License


Languages

Language:Go 100.0%