All Projects → vladimirvivien → Gosh

vladimirvivien / Gosh

Licence: mit
Gosh - a pluggable framework for building command shell programs

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects
golang
3204 projects

Projects that are alternatives of or similar to Gosh

Promptui
Interactive prompt for command-line applications
Stars: ✭ 4,621 (+964.75%)
Mutual labels:  cli, command-line
Kondo
Save disk space by cleaning non-essential files from software projects.
Stars: ✭ 373 (-14.06%)
Mutual labels:  cli, command-line
Reminders Cli
A simple CLI for interacting with macOS reminders
Stars: ✭ 354 (-18.43%)
Mutual labels:  cli, command-line
Gulp Cli
Command Line Interface for gulp.
Stars: ✭ 347 (-20.05%)
Mutual labels:  cli, command-line
Mri
Quickly scan for CLI flags and arguments
Stars: ✭ 394 (-9.22%)
Mutual labels:  cli, command-line
Gandi.cli
command line interface to Gandi.net products using the public API
Stars: ✭ 349 (-19.59%)
Mutual labels:  cli, command-line
Jtc
JSON processing utility
Stars: ✭ 425 (-2.07%)
Mutual labels:  cli, command-line
Fd
A simple, fast and user-friendly alternative to 'find'
Stars: ✭ 19,851 (+4473.96%)
Mutual labels:  cli, command-line
Triage
Interactive command-line GitHub issue & notification triaging tool.
Stars: ✭ 394 (-9.22%)
Mutual labels:  cli, command-line
Pipupgrade
🗽 Like yarn outdated/upgrade, but for pip. Upgrade all your pip packages and automate your Python Dependency Management.
Stars: ✭ 391 (-9.91%)
Mutual labels:  cli, command-line
Cmd2
cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python
Stars: ✭ 342 (-21.2%)
Mutual labels:  cli, command-line
Go Prompt
Building powerful interactive prompts in Go, inspired by python-prompt-toolkit.
Stars: ✭ 4,255 (+880.41%)
Mutual labels:  cli, command-line
Xidel
Command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern matching. It can also create new or transformed XML/HTML/JSON documents.
Stars: ✭ 335 (-22.81%)
Mutual labels:  cli, command-line
Sad
CLI search and replace | Space Age seD
Stars: ✭ 350 (-19.35%)
Mutual labels:  cli, command-line
Go Tea
Tea provides an Elm inspired functional framework for interactive command-line programs.
Stars: ✭ 329 (-24.19%)
Mutual labels:  cli, command-line
Tsukae
🧑‍💻📊 Show off your most used shell commands
Stars: ✭ 345 (-20.51%)
Mutual labels:  cli, command-line
Php Console
🖥 PHP CLI application library, provide console argument parse, console controller/command run, color style, user interactive, format information show and more. 功能全面的PHP命令行应用库。提供控制台参数解析, 命令运行,颜色风格输出, 用户信息交互, 特殊格式信息显示
Stars: ✭ 310 (-28.57%)
Mutual labels:  cli, command-line
Caporal.js
A full-featured framework for building command line applications (cli) with node.js
Stars: ✭ 3,279 (+655.53%)
Mutual labels:  cli, command-line
Beats
A command-line drum machine. Convert a beat notated in YAML into a *.wav file.
Stars: ✭ 389 (-10.37%)
Mutual labels:  cli, command-line
Cocona
Micro-framework for .NET Core console application. Cocona makes it easy and fast to build console applications on .NET Core.
Stars: ✭ 398 (-8.29%)
Mutual labels:  cli, command-line

Gosh - A pluggable interactive shell written Go

Gosh (or Go shell) is a framework that uses Go's plugin system to create for building interactive console-based shell programs. A gosh shell is comprised of a collection of Go plugins which implement one or more commands. When gosh starts, it searches directory ./plugins for available shared object files that implement command plugins.

Getting started

Pre-requisites

  • Go 1.8 or above
  • Linux
  • Mac OSX

Gosh makes it easy to create shell programs. First, download or clone this repository. For a quick start, run the following:

go run shell/gosh.go

This will produce the following output:

                        888
                        888
                        888
 .d88b.  .d88b. .d8888b 88888b.
d88P"88bd88""88b88K     888 "88b
888  888888  888"Y8888b.888  888
Y88b 888Y88..88P     X88888  888
 "Y88888 "Y88P"  88888P'888  888
     888
Y8b d88P
 "Y88P"

No commands found

After the splashscreen is displayed, gosh informs you that no commands found, as expected. Next, exit the gosh shell (Ctrl-C) and let us compile the example plugins that comes with the source code.

go build -buildmode=plugin  -o plugins/sys_command.so plugins/syscmd.go

The previous command will compile plugins/syscmd.go and outputs shared object plugins/sys_command.so, as a Go plugin file. Verify the shared object file was created:

> ls -lh plugins/
total 3.2M
-rw-rw-r-- 1  4.5K Mar 19 18:23 syscmd.go
-rw-rw-r-- 1  3.2M Mar 19 19:14 sys_command.so
-rw-rw-r-- 1  1.4K Mar 19 18:23 testcmd.go

Now, when gosh is restarted, it will dynamically load the commands implemented in the shared object file:

> go run shell/gosh.go
...

Loaded 4 command(s)...
Type help for available commands

gosh>

As indicated, typing help lists all available commands in the shell:

gosh> help

help: prints help information for other commands.

Available commands
------------------
      prompt:	sets a new shell prompt
         sys:	sets a new shell prompt
        help:	prints help information for other commands.
        exit:	exits the interactive shell immediately

Use "help <command-name>" for detail about the specified command

A command

A Gosh Command is represented by type api/Command:

type Command interface {
	Name() string
	Usage() string
	ShortDesc() string
	LongDesc() string
	Exec(context.Context, []string) (context.Context, error)
}

The Gosh framework searches for Go plugin files in the ./plugins directory. Each package plugin must export a variable named Commands which is of type :

type Commands interface {
  ...
	Registry() map[string]Command
}

Type Commands type returns a list of Command via the Registry().

The following shows example command file plugins/testcmd.go. It implements two commands via types helloCmd and goodbyeCmd. The commands are exported via type testCmds using method Registry():

package main

import (
	"context"
	"fmt"
	"io"

	"github.com/vladimirvivien/gosh/api"
)

type helloCmd string

func (t helloCmd) Name() string      { return string(t) }
func (t helloCmd) Usage() string     { return `hello` }
func (t helloCmd) ShortDesc() string { return `prints greeting "hello there"` }
func (t helloCmd) LongDesc() string  { return t.ShortDesc() }
func (t helloCmd) Exec(ctx context.Context, args []string) (context.Context, error) {
	out := ctx.Value("gosh.stdout").(io.Writer)
	fmt.Fprintln(out, "hello there")
	return ctx, nil
}

type goodbyeCmd string

func (t goodbyeCmd) Name() string      { return string(t) }
func (t goodbyeCmd) Usage() string     { return t.Name() }
func (t goodbyeCmd) ShortDesc() string { return `prints message "bye bye"` }
func (t goodbyeCmd) LongDesc() string  { return t.ShortDesc() }
func (t goodbyeCmd) Exec(ctx context.Context, args []string) (context.Context, error) {
	out := ctx.Value("gosh.stdout").(io.Writer)
	fmt.Fprintln(out, "bye bye")
	return ctx, nil
}

// command module
type testCmds struct{}

func (t *testCmds) Init(ctx context.Context) error {
	out := ctx.Value("gosh.stdout").(io.Writer)
	fmt.Fprintln(out, "test module loaded OK")
	return nil
}

func (t *testCmds) Registry() map[string]api.Command {
	return map[string]api.Command{
		"hello":   helloCmd("hello"),
		"goodbye": goodbyeCmd("goodbye"),
	}
}

var Commands testCmds

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].