Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/boreq/guinea

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/boreq/guinea

  • v0.1.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

guinea CI Go Reference

Guinea is a command line interface library.

Description

Programs very often organise the user interface in the form of subcommands. As an example the go command lets the user invoke multiple subcommands such as go build or go get. This library lets you nest any numbers of subcommands (which can be thought of as separate programs) in each other easily building complex user interfaces.

Example

This program implements a root command which displays the program version and two subcommands.

package main

import (
	"fmt"
	"github.com/boreq/guinea"
	"os"
)

var rootCommand = guinea.Command{
	Options: []guinea.Option{
		guinea.Option{
			Name:        "version",
			Type:        guinea.Bool,
			Description: "Display version",
		},
	},
	Run: func(c guinea.Context) error {
		if c.Options["version"].Bool() {
			fmt.Println("v0.0.0-dev")
			return nil
		}
		return guinea.ErrInvalidParms
	},
	Subcommands: map[string]*guinea.Command{
		"display_text": &commandDisplayText,
		"greet":        &commandGreet,
	},
	ShortDescription: "an example program using the guinea library",
	Description:      `This program demonstrates the use of a CLI library.`,
}

var commandDisplayText = guinea.Command{
	Run: func(c guinea.Context) error {
		fmt.Println("Hello world!")
		return nil
	},
	ShortDescription: "displays text on the screen",
	Description:      `This is a subcommand that displays "Hello world!" on the screen.`,
}

var commandGreet = guinea.Command{
	Arguments: []guinea.Argument{
		guinea.Argument{
			Name:        "person",
			Multiple:    false,
			Description: "a person to greet",
		},
	},
	Options: []guinea.Option{
		guinea.Option{
			Name:        "times",
			Type:        guinea.Int,
			Description: "Number of greetings",
			Default:     1,
		},
	},
	Run: func(c guinea.Context) error {
		for i := 0; i < c.Options["times"].Int(); i++ {
			fmt.Printf("Hello %s!\n", c.Arguments[0])
		}
		return nil
	},
	ShortDescription: "greets the specified person",
	Description:      `This is a subcommand that greets the specified person.`,
}

func main() {
	if err := guinea.Run(&rootCommand); err != nil {
		fmt.Fprintln(os.Stderr, err)
	}
}

And here are the example invocations of the program:

$ ./main --help
$ ./main --version
$ ./main display_text
$ ./main hello --help
$ ./main hello boreq
$ ./main hello --times 10 boreq

FAQs

Package last updated on 08 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc