cmdutil

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectCompletions added in v0.9.0

func CollectCompletions(
	prefix string,
	node schema.Node,
	provided map[string]struct{},
	toCompletePrefix string,
	nextArrayIdx func(string) int,
) []cobra.Completion

CollectCompletions recursively walks a schema node and emits a dot-notation "key=" completion for every leaf property. prefix is the dot-path built so far (empty at the top level). Object properties are recursed into; array fields use nextArrayIdx to determine the next index to suggest.

func FormatFor

func FormatFor(cmd *cobra.Command) output.Format

FormatFor returns the output format for a command from the --format flag. The flag's default is set to the user's configured default at startup (see NewRootCmd), so no separate config fallback is required here.

func MakeSchemaArgCompleter added in v0.9.0

func MakeSchemaArgCompleter(modelArgIdx int) func(*cobra.Command, []string, string) ([]cobra.Completion, cobra.ShellCompDirective)

MakeSchemaArgCompleter returns a ValidArgsFunction that provides schema-driven shell completion for key=value positional arguments. modelArgIdx is the index in args that holds the model AIR:

0 → run <model> [key=value ...]
1 → preset save <name> <model> [key=value ...]

When the model has not yet been typed (len(args) <= modelArgIdx), no completions are offered. Once the model is present, the model's JSON Schema is fetched and dot-notation leaf completions are returned for parameters not already provided. Completion is best-effort: failures are silently ignored.

func NewTransport added in v0.7.0

func NewTransport(cmd *cobra.Command, logger *slog.Logger) (transport.Transport, error)

NewTransport dials a transport using the --transport flag on the root command and the API key from config. Callers are responsible for calling Close on the returned transport.

func PrintError added in v0.7.0

func PrintError(logger *log.Logger, err error)

PrintError logs err to logger with appropriate formatting.

Special cases:

  • transport.ErrNoAPIKey → friendly "no key" message with auth hint
  • *transport.RunwareError CodeAuth → "Authentication failed" with auth hint
  • *transport.RunwareError other → re.Message, with docs URL as a "docs" field

For all other errors, err.Error() is used as the message.

func PrintErrorMsg added in v0.7.0

func PrintErrorMsg(logger *log.Logger, message string, err error)

PrintErrorMsg logs a custom message to logger, appending the documentation URL from err as a "docs" field when err is a *transport.RunwareError with one. Use this when a command needs to surface a context-specific message for an error but continue executing (warning-style) rather than exit.

Types

This section is empty.

Jump to

Keyboard shortcuts

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