• Stars
    star
    525
  • Rank 84,404 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A powerful modern CLI and SHELL

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: We do not guarantee 100% backwards compatiblity between minor versions (1.x). However, the API is mostly stable and should not change much.

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"},

    Flags: func(f *grumble.Flags) {
        f.Duration("t", "timeout", time.Second, "timeout duration")
    },

    Args: func(a *grumble.Args) {
        a.String("service", "which service to start", grumble.Default("server"))
    },

    Run: func(c *grumble.Context) error {
        // Parent Flags.
        c.App.Println("directory:", c.Flags.String("directory"))
        c.App.Println("verbose:", c.Flags.Bool("verbose"))
        // Flags.
        c.App.Println("timeout:", c.Flags.Duration("timeout"))
        // Args.
        c.App.Println("service:", c.Args.String("service"))
        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

Separate flags and args specifically

If you need to pass a flag-like value as positional argument, you can do so by using a double dash:
>>> command --flag1=something -- --myPositionalArg

Remote shell access with readline

By calling RunWithReadline() rather than Run() you can pass instance of readline.Instance. One of interesting usages is having a possibility of remote access to your shell:

handleFunc := func(rl *readline.Instance) {

    var app = grumble.New(&grumble.Config{
        // override default interrupt handler to avoid remote shutdown
        InterruptHandler: func(a *grumble.App, count int) {
            // do nothing
        },
		
        // your usual grumble configuration
    })  
    
    // add commands
	
    app.RunWithReadline(rl)

}

cfg := &readline.Config{}
readline.ListenRemote("tcp", ":5555", cfg, handleFunc)

In the client code just use readline built in DialRemote function:

if err := readline.DialRemote("tcp", ":5555"); err != nil {
    fmt.Errorf("An error occurred: %s \n", err.Error())
}

Samples

Check out the sample directory for some detailed examples.

Projects using Grumble

Known issues

  • Windows unicode not fully supported (issue)

Additional Useful Packages

Credits

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

License

MIT

More Repositories

1

glue

Glue - Robust Go and Javascript Socket Library (Alternative to Socket.io)
Go
415
star
2

fillpdf

FillPDF - Fill PDF forms
Go
80
star
3

openrazer-drivers

Razer Linux Kernel Drivers
C
36
star
4

timer

Go Timer implementation with a fixed Reset behavior
Go
33
star
5

pakt

Interlink Remote Applications
Go
21
star
6

gml

MIT licensed Go QML Bindings
Go
18
star
7

orbit

ORBIT - Interlink Remote Applications
Go
15
star
8

grml

A simple build automation tool written in Go
Go
14
star
9

binarysocket

BinarySocket is a real-time bidirectional binary socket library for the web
Go
10
star
10

crossbuild

Docker Crossbuild Images
Dockerfile
7
star
11

closer

A simple, thread-safe closer for go
Go
6
star
12

docker-golang-gb

Golang GB Docker Image
5
star
13

event

A simple event emitter for Go
Go
4
star
14

bulldozer

Bulldozer - A Rock Solid and Secure Web Framework
Go
4
star
15

turban

Turban Shell - A simple shell experience.
Go
4
star
16

bitmonster

BitMonster - A Monster handling your Bits - A powerful platform for your real-time mobile or web application
Go
3
star
17

photon

Build powerful crossplatform Web Apps
C++
3
star
18

watchman

Simple HTTP Reverse Proxy with authentication
Go
3
star
19

docker-samba

A secure samba docker image
Shell
2
star
20

proton

Proton - A powerful platform for your real-time web applications
Go
2
star
21

ants

ANTS - Asynchronous binary data protocol for communication - Let the ants handle your serial communication
Go
1
star
22

docker-nginx

Deploy Nginx with some useful presets available.
Nginx
1
star
23

openrazer-drivers-legacy

Legacy Razer Linux Kernel Drivers
C
1
star
24

docker-bulldozer

Dockerfile for Bulldozer applications
Shell
1
star
25

grpc-vs-orbit

Go
1
star
26

ddns

Dynamic DNS Service
Go
1
star
27

wego

A go client to the Wekan REST API
Go
1
star
28

openrazer

OpenRazer Daemon & Tools
Go
1
star