stdcli

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Help

func Help(c *Context) error

func IsTerminal

func IsTerminal(f *os.File) bool

Types

type CmdExecutor

type CmdExecutor struct {
}

func (*CmdExecutor) Execute

func (e *CmdExecutor) Execute(cmd string, args ...string) ([]byte, error)

func (*CmdExecutor) Run

func (e *CmdExecutor) Run(w io.Writer, cmd string, args ...string) error

func (*CmdExecutor) Terminal

func (e *CmdExecutor) Terminal(cmd string, args ...string) error

type Command

type Command struct {
	Command     []string
	Description string
	Flags       []Flag
	Invisible   bool
	Handler     HandlerFunc
	Usage       string
	Validate    Validator
	// contains filtered or unexported fields
}

func (*Command) ExecuteContext

func (c *Command) ExecuteContext(ctx context.Context, args []string) error

func (*Command) FullCommand

func (c *Command) FullCommand() string

func (*Command) Match

func (c *Command) Match(args []string) ([]string, bool)

type CommandOptions

type CommandOptions struct {
	Flags     []Flag
	Invisible bool
	Usage     string
	Validate  Validator
}

type Context

type Context struct {
	context.Context

	Args  []string
	Flags []*Flag
	// contains filtered or unexported fields
}

func (*Context) Arg

func (c *Context) Arg(i int) string

func (*Context) Bool

func (c *Context) Bool(name string) bool

func (*Context) Error

func (c *Context) Error(err error) error

func (*Context) Errorf

func (c *Context) Errorf(format string, args ...interface{}) error

func (*Context) Execute

func (c *Context) Execute(cmd string, args ...string) ([]byte, error)

func (*Context) Fail

func (c *Context) Fail(err error)

func (*Context) Flag

func (c *Context) Flag(name string) *Flag

func (*Context) Info

func (c *Context) Info() *Info

func (*Context) Int

func (c *Context) Int(name string) int

func (*Context) LocalSetting

func (c *Context) LocalSetting(name string) string

func (*Context) OK

func (c *Context) OK(id ...string) error

func (*Context) Options

func (c *Context) Options(opts interface{}) error

func (*Context) Read

func (c *Context) Read(data []byte) (int, error)

func (*Context) ReadSecret

func (c *Context) ReadSecret() (string, error)

func (*Context) Reader

func (c *Context) Reader() *Reader

func (*Context) Run

func (c *Context) Run(cmd string, args ...string) error

func (*Context) SettingDelete

func (c *Context) SettingDelete(name string) error

func (*Context) SettingDirectory

func (c *Context) SettingDirectory(name string) (string, error)

func (*Context) SettingRead

func (c *Context) SettingRead(name string) (string, error)

func (*Context) SettingReadKey

func (c *Context) SettingReadKey(name, key string) (string, error)

func (*Context) SettingWrite

func (c *Context) SettingWrite(name, value string) error

func (*Context) SettingWriteKey

func (c *Context) SettingWriteKey(name, key, value string) error

func (*Context) Startf

func (c *Context) Startf(format string, args ...interface{})

func (*Context) String

func (c *Context) String(name string) string

func (*Context) Table

func (c *Context) Table(columns ...string) *Table

func (*Context) Terminal

func (c *Context) Terminal(cmd string, args ...string) error

func (*Context) TerminalRaw

func (c *Context) TerminalRaw() func()

func (*Context) TerminalSize

func (c *Context) TerminalSize() (int, int, error)

func (*Context) Value

func (c *Context) Value(name string) interface{}

func (*Context) Version

func (c *Context) Version() string

func (*Context) Write

func (c *Context) Write(data []byte) (int, error)

func (*Context) Writef

func (c *Context) Writef(format string, args ...interface{}) error

func (*Context) Writer

func (c *Context) Writer() *Writer

type Engine

type Engine struct {
	Commands []Command
	Executor Executor
	Name     string
	Profile  string
	Reader   *Reader
	Settings string
	Version  string
	Writer   *Writer
}

func New

func New(name, version string) *Engine

func (*Engine) Command

func (e *Engine) Command(command, description string, fn HandlerFunc, opts CommandOptions)

func (*Engine) Execute

func (e *Engine) Execute(args []string) int

func (*Engine) ExecuteContext

func (e *Engine) ExecuteContext(ctx context.Context, args []string) int

func (*Engine) LocalSetting

func (e *Engine) LocalSetting(name string) string

func (*Engine) SettingDelete

func (e *Engine) SettingDelete(name string) error

func (*Engine) SettingDirectory

func (e *Engine) SettingDirectory(name string) (string, error)

func (*Engine) SettingRead

func (e *Engine) SettingRead(name string) (string, error)

func (*Engine) SettingReadKey

func (e *Engine) SettingReadKey(name, key string) (string, error)

func (*Engine) SettingWrite

func (e *Engine) SettingWrite(name, value string) error

func (*Engine) SettingWriteKey

func (e *Engine) SettingWriteKey(name, key, value string) error

type Executor

type Executor interface {
	Execute(cmd string, args ...string) ([]byte, error)
	Run(w io.Writer, cmd string, args ...string) error
	Terminal(cmd string, args ...string) error
}

type ExitCode

type ExitCode struct {
	// contains filtered or unexported fields
}

func Exit

func Exit(code int) ExitCode

func (ExitCode) Code

func (e ExitCode) Code() int

func (ExitCode) Error

func (e ExitCode) Error() string

type ExitCoder

type ExitCoder interface {
	Code() int
}

type Flag

type Flag struct {
	Default     interface{}
	Description string
	Name        string
	Short       string
	Value       interface{}
	// contains filtered or unexported fields
}

func BoolFlag

func BoolFlag(name, short, description string) Flag

func DurationFlag

func DurationFlag(name, short, description string) Flag

func IntFlag

func IntFlag(name, short, description string) Flag

func OptionFlags

func OptionFlags(opts interface{}) []Flag

func StringFlag

func StringFlag(name, short, description string) Flag

func (*Flag) Set

func (f *Flag) Set(v string) error

func (*Flag) String

func (f *Flag) String() string

func (*Flag) Type

func (f *Flag) Type() string

func (*Flag) Usage

func (f *Flag) Usage(v string) string

func (*Flag) UsageLong

func (f *Flag) UsageLong() string

func (*Flag) UsageShort

func (f *Flag) UsageShort() string

type HandlerFunc

type HandlerFunc func(*Context) error

type Info

type Info struct {
	Context *Context
	Rows    []InfoRow
}

func (*Info) Add

func (i *Info) Add(header, value string)

func (*Info) Print

func (i *Info) Print() error

type InfoRow

type InfoRow struct {
	Header string
	Value  string
}

type Reader

type Reader struct {
	io.Reader
}
var (
	DefaultReader *Reader
)

func (*Reader) IsTerminal

func (r *Reader) IsTerminal() bool

func (*Reader) TerminalRaw

func (r *Reader) TerminalRaw() func() bool

type Renderer

type Renderer func(string) string

func RenderColors

func RenderColors(colors ...int) Renderer

func RenderUnderline

func RenderUnderline() Renderer

type Table

type Table struct {
	Columns []string
	Context *Context
	Rows    [][]string
}

func (*Table) AddRow

func (t *Table) AddRow(row ...string)

func (*Table) Print

func (t *Table) Print() error

type Validator

type Validator func(c *Context) error

func Args

func Args(num int) Validator

func ArgsBetween

func ArgsBetween(min, max int) Validator

func ArgsMax

func ArgsMax(max int) Validator

func ArgsMin

func ArgsMin(min int) Validator

type Writer

type Writer struct {
	Color  bool
	Stdout io.Writer
	Stderr io.Writer
	Tags   map[string]Renderer
}
var (
	DefaultWriter *Writer
)

func (*Writer) Error

func (w *Writer) Error(err error) error

func (*Writer) Errorf

func (w *Writer) Errorf(format string, args ...interface{}) error

func (*Writer) IsTerminal

func (w *Writer) IsTerminal() bool

func (*Writer) Sprintf

func (w *Writer) Sprintf(format string, args ...interface{}) string

func (*Writer) Write

func (w *Writer) Write(data []byte) (int, error)

func (*Writer) Writef

func (w *Writer) Writef(format string, args ...interface{}) (int, error)

Jump to

Keyboard shortcuts

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