gocli

package module
v0.0.0-...-6d0b942 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2016 License: Apache-2.0 Imports: 12 Imported by: 77

README

gocli

Build Status

Golang library for CLI applications

Documentation

Index

Constants

View Source
const (
	STRING  = "string"
	INTEGER = "int"
	BOOL    = "bool"
)
View Source
const (
	BLACK = iota
	RED
	GREEN
	YELLOW
	BLUE
	MAGENTA
	CYAN
	WHITE
)

Variables

This section is empty.

Functions

func AddActionUsage

func AddActionUsage(parts []string, table *Table, action *Action)

func Black

func Black(s string) string

func Blue

func Blue(s string) string

func Colorize

func Colorize(c int, s string) (r string)

func Cyan

func Cyan(s string) string

func Green

func Green(s string) string

func Magenta

func Magenta(s string) string

func Red

func Red(s string) string

func White

func White(s string) string

func Yellow

func Yellow(s string) string

Types

type Action

type Action struct {
	Handler     func(*Args) error
	Args        *Args
	Description string
	Usage       string
}

type Args

type Args struct {
	Args       []string
	Attributes map[string][]string

	FlagMap     FlagMap
	ArgumentMap ArgumentMap
	Flags       []*Flag
	// contains filtered or unexported fields
}

func NewArgs

func NewArgs(mapping FlagMap) *Args

func (*Args) AddAttribute

func (a *Args) AddAttribute(k, v string)

func (*Args) AddFlag

func (a *Args) AddFlag(key, value string)

func (*Args) AttributesMap

func (a *Args) AttributesMap() map[string]string

func (*Args) Bool

func (a *Args) Bool(key string)

func (*Args) BuildStringFlag

func (a *Args) BuildStringFlag(key string, required bool, defaultValue, description string) *Flag

func (*Args) Get

func (a *Args) Get(key string) []string

func (*Args) GetBool

func (a *Args) GetBool(key string) bool

func (*Args) GetInt

func (a *Args) GetInt(key string) (int, error)

func (*Args) GetString

func (a *Args) GetString(key string) (string, error)

func (*Args) KeyForCliKey

func (a *Args) KeyForCliKey(cliKey string) string

func (*Args) Length

func (a *Args) Length() int

func (*Args) MustGetInt

func (a *Args) MustGetInt(key string) int

func (*Args) MustGetString

func (a *Args) MustGetString(key string) string

func (*Args) Parse

func (a *Args) Parse(args []string) error

func (*Args) RegisterArgs

func (a *Args) RegisterArgs(args string)

func (*Args) RegisterBool

func (a *Args) RegisterBool(cliKey string, key string, required bool, defaultValue bool, description string)

func (*Args) RegisterFlag

func (a *Args) RegisterFlag(flag *Flag)

func (*Args) RegisterInt

func (a *Args) RegisterInt(cliKey string, key string, required bool, defaultValue int, description string)

func (*Args) RegisterString

func (a *Args) RegisterString(cliKey string, key string, required bool, defaultValue, description string)

func (*Args) String

func (a *Args) String(key string)

func (*Args) TypeOf

func (a *Args) TypeOf(key string) (out string, e error)

func (*Args) Usage

func (a *Args) Usage() string

type Argument

type Argument struct {
	Key      string
	Index    int
	Multiple bool
}

type ArgumentMap

type ArgumentMap map[string]*Argument

type Flag

type Flag struct {
	Type         string
	Key          string
	CliFlag      string
	Required     bool
	DefaultValue string
	Description  string
}

func (*Flag) Matches

func (f *Flag) Matches(key string) bool

func (*Flag) Usage

func (f *Flag) Usage() []string

type FlagMap

type FlagMap map[string]*Flag

type Router

type Router struct {
	Actions   map[string]*Action
	Separator string
	Writer    io.Writer
}

func NewRouter

func NewRouter(mapping map[string]*Action) *Router

func (*Router) Handle

func (cli *Router) Handle(raw []string) error

func (*Router) Println

func (router *Router) Println(a ...interface{})

func (*Router) Register

func (cli *Router) Register(path string, action *Action)

func (*Router) Search

func (router *Router) Search(patterns []string) map[string]*Action

func (*Router) Usage

func (cli *Router) Usage() string

func (*Router) UsageForKeys

func (cli *Router) UsageForKeys(keys []string, pattern string) string

type Table

type Table struct {
	Columns   [][]string
	Separator string

	SortBy int
	// contains filtered or unexported fields
}

func NewTable

func NewTable() *Table

func (*Table) Add

func (t *Table) Add(cols ...interface{})

Add adds a column to the table

func (*Table) AddP

func (t *Table) AddP(cols ...interface{})

Dereferencing pointers if not nil TODO: Please someone tell me, how to do this right!

func (*Table) AddStrings

func (t *Table) AddStrings(list []string)

func (*Table) Header

func (t *Table) Header(cols ...interface{})

func (*Table) Len

func (t *Table) Len() int

func (*Table) Less

func (t *Table) Less(a, b int) bool

func (*Table) Lines

func (t *Table) Lines(printIndex bool) (lines []string)

func (*Table) Select

func (t *Table) Select(message string) int

func (*Table) String

func (t *Table) String() string

func (*Table) StringWithIndex

func (t *Table) StringWithIndex() string

func (*Table) Swap

func (t *Table) Swap(a, b int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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