cli

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tokenize

func Tokenize(input string) ([]string, error)

Tokenize split command input to string array

Removes quotes where required Example:

  • cmd --flag1="value1" "arg arg" -> []string{"cmd", "--flag1=value1", "arg arg"}

Types

type Cli

type Cli interface {
	OneCmd(input string) error   // Process one command
	AddCmd(commands ...*Command) // Adds one or more commands
}

Cli command processer

func NewCli

func NewCli() Cli

type Command

type Command struct {
	Use   string
	Flags []*CommandFlag
	Desc  Description
	Run   func(flags map[string]*ParsedCommandFlags, args []string)
}

Command structure representing a command

func (*Command) GetFlag

func (c *Command) GetFlag(flag string) *CommandFlag

Returns a flag by type name. Returns a flag by type name. If it does not exist, then nil.

type CommandFlag

type CommandFlag struct {
	Type  string // flag id
	Long  string // for '--flag'
	Short string // for '-f'
	Desc  Description
}

CommandFlag structure representing flag for command

type CommandParser

type CommandParser interface {
	ParseCommand(input string) (*ParsedCommand, error) // ParseCommand parses a string representing a command of the form <command> <flags> <args>
}

CommandParser implements a method for parsing commands of the form <command> <flags> <args> into a ParsedCommand structure

func NewCommandParser

func NewCommandParser() CommandParser

type Description

type Description struct {
	Long  string
	Short string
}

Description of command or flag or something else

type ParsedCommand

type ParsedCommand struct {
	Name  string // same as Use in Command
	Flags map[string]*ParsedCommandFlags
	Args  []string
}

type ParsedCommandFlags

type ParsedCommandFlags struct {
	Type string
	Name string
	Args string
}

Jump to

Keyboard shortcuts

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