stdcli

package module
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 CommandDefinition added in v1.1.0

type CommandDefinition struct {
	Command     string
	Description string
	Handler     HandlerFunc
	Options     CommandOptions
}

type CommandDefinitions added in v1.1.0

type CommandDefinitions []CommandDefinition

func (CommandDefinitions) Apply added in v1.1.0

func (cs CommandDefinitions) Apply(e *Engine)

func (*CommandDefinitions) Register added in v1.1.0

func (cs *CommandDefinitions) Register(command, description string, fn HandlerFunc, opts CommandOptions)

type CommandOptions

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

type Context

type Context interface {
	context.Context
	io.ReadWriter

	Arg(i int) string
	Args() []string
	Cleanup(func())
	Execute(cmd string, args ...string) ([]byte, error)
	Flags() Flags
	Info() InfoWriter
	IsTerminal() bool
	IsTerminalReader() bool
	IsTerminalWriter() bool
	ReadSecret() (string, error)
	Run(cmd string, args ...string) error
	Table(columns ...any) TableWriter
	Terminal(cmd string, args ...string) error
	Version() string
	Writef(format string, args ...any)
}

type Engine

type Engine struct {
	Commands []Command
	Executor Executor
	Name     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

type Executor

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

type ExitCoder

type ExitCoder interface {
	ExitCode() int
}

func Exit

func Exit(code int) ExitCoder

type Flag

type Flag struct {
	Default     any
	Description string
	Name        string
	Short       string
	Value       any
	// 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 any) []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 Flags added in v1.1.0

type Flags []*Flag

func (Flags) Bool added in v1.1.0

func (fs Flags) Bool(name string) bool

func (Flags) Int added in v1.1.0

func (fs Flags) Int(name string) int

func (Flags) String added in v1.1.0

func (fs Flags) String(name string) string

func (Flags) Value added in v1.1.0

func (fs Flags) Value(name string) any

type HandlerFunc

type HandlerFunc func(Context) error

type InfoWriter added in v1.1.0

type InfoWriter interface {
	Add(header, value string)
	Print() error
}

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 TableWriter added in v1.1.0

type TableWriter interface {
	Append(row ...any)
	Print() error
}

type Validator

type Validator func(ctx 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 ...any) error

func (*Writer) IsTerminal

func (w *Writer) IsTerminal() bool

func (*Writer) Sprintf

func (w *Writer) Sprintf(format string, args ...any) string

func (*Writer) Write

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

func (*Writer) Writef

func (w *Writer) Writef(format string, args ...any) (int, error)

Jump to

Keyboard shortcuts

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