cmd

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const GlobalFlags = "global"
View Source
const IgnoreError = -1
View Source
const JwtParam = "jwt"
View Source
const StatusParam = "status_code"

Variables

This section is empty.

Functions

func RegisterCommand

func RegisterCommand(name string, c Command)

RegisterCommand registers a Command implementation under the given extension class name (the value returned by Method.GetExtensionClass(), which maps to the "class" field of an operation's extension in the OpenAPI spec).

This lets a program that imports tcli as a library add its own command types (e.g. for publishing to a queue or topic) without needing to copy source files into this package. Call it from an init() in your own package, then blank-import that package from your main so the init() runs:

package mypubsub

func init() {
    cmd.RegisterCommand("sqs", &SqsCommand{})
}

// in your main package
import _ "example.com/myclient/mypubsub"

Types

type CmdBase

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

func (*CmdBase) Execute

func (c *CmdBase) Execute() error

func (*CmdBase) GetBase

func (c *CmdBase) GetBase() *CmdBase

func (*CmdBase) Global

func (c *CmdBase) Global() *GlobalResult

Global returns the parsed global flag values for this command.

func (*CmdBase) InitBase

func (c *CmdBase) InitBase(p *ParseResult, f func() error)

InitBase initializes a CmdBase from outside this package. Custom Command implementations registered via RegisterCommand should call this from their Init method instead of reimplementing CmdBase's plumbing:

func (c *MyCommand) Init(p *cmd.ParseResult) cmd.Command {
    k := MyCommand{}
    k.InitBase(p, k.run)
    return &k
}

func (*CmdBase) Params

func (c *CmdBase) Params() *ParseResult

Params returns the parsed parameter values for this command, so external Command implementations can read parameters without needing direct access to CmdBase's unexported fields.

func (*CmdBase) Stop added in v0.0.5

func (c *CmdBase) Stop() <-chan struct{}

Stop returns a channel that is closed once another job in the run has failed. Long running commands, such as ones that retry, should give up when it closes. It is nil (never closes) outside an Environment.

type Command

type Command interface {
	Init(*ParseResult) Command
	Execute() error
	GetBase() *CmdBase
}

func GetCommand

func GetCommand(name string) (Command, error)

type EchoCommand

type EchoCommand struct {
	CmdBase
}

func (*EchoCommand) Init

func (c *EchoCommand) Init(p *ParseResult) Command

type Environment

type Environment struct {
	Args     []string
	Parallel *ParallelEnvironment
	// contains filtered or unexported fields
}

Environment runs commands and fails fast: the first error stops new jobs and input records from starting. Jobs already running finish their current attempt but do not retry. Wait reports every error.

func GetExecutionEnv

func GetExecutionEnv(args []string) *Environment

func (*Environment) Exec

func (e *Environment) Exec(m *parser.Method, i *common.Input) error

Exec runs the method for one input record. Errors are recorded and reported by Wait as well as returned.

func (*Environment) Stopped added in v0.0.5

func (e *Environment) Stopped() bool

Stopped reports whether a job has failed, meaning no further jobs or input records should be started.

func (*Environment) Wait

func (e *Environment) Wait() error

Wait blocks until all jobs finish and returns every job error joined, or nil if all jobs succeeded.

type GlobalResult

type GlobalResult struct {
	Count       uint
	RetryCount  int64
	BasePath    string
	Scheme      string
	Server      string
	Doc         string
	Format      string
	Verbose     bool
	Parallel    bool
	IgnoreError bool
	Trace       bool
}

type HttpCommand

type HttpCommand struct {
	CmdBase
}

func (*HttpCommand) Init

func (c *HttpCommand) Init(p *ParseResult) Command

type ParallelEnvironment

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

type ParseResult

type ParseResult struct {
	Path   string
	Flags  *flag.FlagSet
	Values common.Values
	Method *parser.Method
	Global *GlobalResult
}

func New

func New(o *parser.Method, in *common.Input, r *parser.Root) *ParseResult

New creates a new ParseResult and initializes the flag set with the parameters from the given method and global flags.

func (*ParseResult) ValidateParams

func (p *ParseResult) ValidateParams() error

ValidateParams checks that all required parameters have values and sets global configuration options based on the parsed values.

type TcpCommand

type TcpCommand struct {
	CmdBase
}

func (*TcpCommand) Init

func (c *TcpCommand) Init(p *ParseResult) Command

Jump to

Keyboard shortcuts

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