cli

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const ExitUsage = 2

ExitUsage is the status for a bad flag, a missing argument, or an unknown subcommand.

View Source
const MaxTextWidth = 100

MaxTextWidth caps wrapped CLI text output at a readable line length.

Variables

View Source
var ErrHelp = flag.ErrHelp

ErrHelp is returned when Parse sees -h or --help.

View Source
var ErrRunRequestChoiceCanceled = errors.New("request selection canceled")

Functions

func CleanExecPath added in v0.28.1

func CleanExecPath(path string) string

func CommandFileConflict

func CommandFileConflict(app, name, hint string) error

func DetectWidth added in v0.46.1

func DetectWidth(w io.Writer) int

DetectWidth resolves the terminal width. COLUMNS overrides everything, otherwise writer, the standard streams and finally /dev/tty are probed so a redirected stderr still yields the real width. defaultWidth is the last resort.

func ExitCode

func ExitCode(err error) int

func HasFileConflict

func HasFileConflict(name string) bool

func IsExitCodeOnly added in v0.36.1

func IsExitCodeOnly(err error) bool

IsExitCodeOnly reports whether err is only an exit-code carrier.

Commands use this after they have already written their output and need to return a non-zero process status without producing another stderr diagnostic.

func IsHelpArg added in v1.11.0

func IsHelpArg(arg string) bool

IsHelpArg matches -h and --help exactly because -H can be a real flag.

func NewExecClient added in v0.28.1

func NewExecClient(version string, f ExecFlags) (*httpx.Client, func() error, error)

func ParseCompareTargets

func ParseCompareTargets(raw string) ([]string, error)

func ParseRunDoc added in v0.28.1

func ParseRunDoc(src RunSource) (*restfile.Document, error)

func PrintFlagDefaults added in v0.39.4

func PrintFlagDefaults(w io.Writer, fs *FlagSet)

func PrintFlagSetUsage

func PrintFlagSetUsage(w io.Writer, app string, fs *FlagSet)

func StdinRunPath added in v0.28.1

func StdinRunPath(workspace string) string

StdinRunPath gives stdin-backed runs a stable request-file path so relative resolution still has a workspace anchor.

func UsageError added in v1.13.1

func UsageError(err error) error

func WriteRunRequestChoices added in v0.28.1

func WriteRunRequestChoices(
	w io.Writer,
	path string,
	choices []RunRequestChoice,
) error

func WriteTextStyled added in v0.29.2

func WriteTextStyled(
	w io.Writer,
	rep *runfmt.Report,
	color termcolor.Config,
	def *theme.Definition,
) error

WriteTextStyled writes a runfmt text report with CLI-owned ANSI styling.

Types

type ExecConfig added in v0.28.1

type ExecConfig struct {
	FilePath  string
	Workspace string
	Recursive bool
	Env       vars.Config
	HTTPOpts  httpx.Options
	GRPCOpts  grpcx.Options
	Compare   engine.CompareConfig
}

type ExecFlags added in v0.28.1

type ExecFlags struct {
	EnvName           string
	EnvFile           string
	Workspace         string
	Timeout           time.Duration
	Insecure          bool
	Follow            bool
	ProxyURL          string
	MaxResponseSize   string
	MaxRedirects      int
	Recursive         bool
	CompareTargetsRaw string
	CompareBaseline   string
	CompareGroup      string
	EnvGroups         GroupFlags
	// contains filtered or unexported fields
}

func NewExecFlags added in v0.28.1

func NewExecFlags() ExecFlags

func (*ExecFlags) Bind added in v0.28.1

func (f *ExecFlags) Bind(fs *FlagSet)

func (*ExecFlags) BindTelemetryFlags added in v0.28.1

func (f *ExecFlags) BindTelemetryFlags(fs *FlagSet)

func (ExecFlags) Resolve added in v0.28.1

func (f ExecFlags) Resolve(filePath string) (ExecConfig, error)

Resolve builds a run configuration and requires a valid environment file.

func (ExecFlags) ResolveSession added in v1.2.1

func (f ExecFlags) ResolveSession(filePath string) (ExecConfig, error)

ResolveSession builds an editor configuration. Parse errors are returned in Env.FileErr so the editor can open the file, while other load errors remain fatal. Requests stay blocked until the file parses successfully.

func (ExecFlags) TelemetryConfig added in v0.28.1

func (f ExecFlags) TelemetryConfig(version string) telemetry.Config

func (ExecFlags) ValidateEnvFlag added in v0.28.1

func (f ExecFlags) ValidateEnvFlag() error

type ExitErr

type ExitErr struct {
	Err  error
	Code int
}

func (ExitErr) Error

func (e ExitErr) Error() string

func (ExitErr) ExitCode

func (e ExitErr) ExitCode() int

func (ExitErr) Unwrap

func (e ExitErr) Unwrap() error

type FlagSet added in v1.5.6

type FlagSet struct {
	*flag.FlagSet
	// contains filtered or unexported fields
}

FlagSet accepts flags before or after positional arguments. String flags are trimmed.

func NewFlagSet

func NewFlagSet(name string) *FlagSet

func NewSubcommandFlagSet

func NewSubcommandFlagSet(app, name string, w io.Writer) *FlagSet

func (*FlagSet) Arg added in v1.5.6

func (f *FlagSet) Arg(i int) string

func (*FlagSet) Args added in v1.5.6

func (f *FlagSet) Args() []string

Args returns the positional arguments in their original order.

func (*FlagSet) BoolVarAliases added in v1.5.6

func (f *FlagSet) BoolVarAliases(dst *bool, value bool, usage string, names ...string)

func (*FlagSet) DurationVarAliases added in v1.5.6

func (f *FlagSet) DurationVarAliases(dst *time.Duration, value time.Duration, usage string, names ...string)

func (*FlagSet) IntVarAliases added in v1.5.6

func (f *FlagSet) IntVarAliases(dst *int, value int, usage string, names ...string)

func (*FlagSet) NArg added in v1.5.6

func (f *FlagSet) NArg() int

func (*FlagSet) Parse added in v1.5.6

func (f *FlagSet) Parse(args []string) error

Parse accepts flags before or after positional arguments until "--".

func (*FlagSet) StringListVarAliases added in v1.5.6

func (f *FlagSet) StringListVarAliases(dst *[]string, usage string, names ...string)

func (*FlagSet) StringVar added in v1.5.6

func (f *FlagSet) StringVar(dst *string, name, value, usage string)

func (*FlagSet) StringVarAliases added in v1.5.6

func (f *FlagSet) StringVarAliases(dst *string, value, usage string, names ...string)

func (*FlagSet) UnexpectedArgs added in v1.5.6

func (f *FlagSet) UnexpectedArgs() error

UnexpectedArgs returns an error if the command received positional arguments.

func (*FlagSet) WasSet added in v1.5.6

func (f *FlagSet) WasSet(name string) bool

WasSet reports whether the flag, or one of its aliases, appeared in the arguments, even when its value is the same as the default.

type GroupFlags added in v0.49.1

type GroupFlags map[string]string

func (*GroupFlags) Set added in v0.49.1

func (f *GroupFlags) Set(value string) error

func (GroupFlags) String added in v0.49.1

func (f GroupFlags) String() string

type RecordFlags added in v1.8.0

type RecordFlags struct {
	Config recorder.Config
	// contains filtered or unexported fields
}

func NewRecordFlags added in v1.8.0

func NewRecordFlags() RecordFlags

func (*RecordFlags) Bind added in v1.8.0

func (f *RecordFlags) Bind(fs *FlagSet)

func (RecordFlags) Resolve added in v1.8.0

func (f RecordFlags) Resolve() (recorder.Config, error)

type RunRequestChoice added in v0.28.1

type RunRequestChoice struct {
	Line   int
	Method string
	Name   string
	Target string
	Label  string
}

func BuildRunRequestChoices added in v0.28.1

func BuildRunRequestChoices(doc *restfile.Document) []RunRequestChoice

func PromptRunRequestChoice added in v0.28.1

func PromptRunRequestChoice(
	r io.Reader,
	w io.Writer,
	path string,
	choices []RunRequestChoice,
	opt RunRequestPromptOptions,
) (RunRequestChoice, error)

type RunRequestPromptOptions added in v0.28.1

type RunRequestPromptOptions struct {
	TTY   bool
	Color termcolor.Config
	Theme *theme.Definition
}

type RunSource added in v0.28.1

type RunSource struct {
	Path  string
	Data  []byte
	Stdin bool
}

Jump to

Keyboard shortcuts

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