stdcli

package module
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 CommandDefinition

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

type CommandDefinitions

type CommandDefinitions []CommandDefinition

func (CommandDefinitions) Apply

func (cs CommandDefinitions) Apply(e *Engine)

func (*CommandDefinitions) Register

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
	Execute(cmd string, args ...string) ([]byte, error)
	Flags() Flags
	InfoWriter() InfoWriter
	ReadSecret() (string, error)
	Run(cmd string, args ...string) error
	Terminal(cmd string, args ...string) error
	Version() string
	Writef(format string, args ...any) error
}

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(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     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

type Flags []Flag

func (Flags) Bool

func (fs Flags) Bool(name string) bool

func (Flags) Int

func (fs Flags) Int(name string) int

func (Flags) String

func (fs Flags) String(name string) string

func (Flags) Value

func (fs Flags) Value(name string) any

type HandlerFunc

type HandlerFunc func(Context) error

type InfoWriter

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

type TableWriter interface {
	Append(row ...string)
	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 ...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