cli_utils

package module
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

cli-utils

Go Reference

cli-utils is a simple Go package to create command line interfaces.

Installation

To install the package, use the following command:

go get github.com/lazarcloud/cli-utils

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HelpCommand = Command{
	Name:        "help",
	Description: "Helps you with a command",
	Run:         RunHelp,
	Args: []Arg{
		{
			Name:        "command",
			Description: "Command to get help for",
			Required:    false,
			Default:     nil,
		},
	},
}

Functions

func ReadInput

func ReadInput() (string, error)

func RunHelp

func RunHelp(args RuntimeArgs, c *CLI) error

Types

type Arg

type Arg struct {
	Name        string
	Description string
	Required    bool
	Default     interface{}
	Check       func(arg *Arg, value string) error
}

type Args

type Args []Arg

type CLI

type CLI struct {
	Name           string
	DefaultCommand *Command
	Commands       []Command
}

func NewCLI

func NewCLI(name string, commands Commands, defaultCommand *Command) *CLI

func (*CLI) GetCommand

func (c *CLI) GetCommand(name string) *Command

func (*CLI) HasCommand

func (c *CLI) HasCommand(name string) bool

func (*CLI) Run

func (c *CLI) Run() error

type Command

type Command struct {
	Name        string
	Description string
	Run         func(args RuntimeArgs, c *CLI) error
	CleanUp     func(args RuntimeArgs, c *CLI) error
	Args        Args
}

type Commands

type Commands []Command

type RuntimeArgs

type RuntimeArgs map[string]interface{}

func (RuntimeArgs) Get

func (r RuntimeArgs) Get(name string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL