cmd

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package cmd is the cobra command tree for the stackr CLI. It replaces the hand-rolled dispatch in internal/cli/run.go (see docs/plans/07-cli-ux-rewrite.md and docs/plans/08-cli-ux-matrices.md).

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelled = errors.New("cancelled")

ErrCancelled is returned when the user declines a confirm.

Functions

func Execute

func Execute() int

Execute runs the CLI and returns the process exit code. Fang owns the signal context, --version, completions, and error rendering.

func ExitCode

func ExitCode(err error) int

ExitCode maps the error returned by Execute to a process exit code.

func NewRoot

func NewRoot(rt *Runtime) *cobra.Command

NewRoot builds the command tree over rt. IO goes through rt so tests can capture it.

func RewriteArgs

func RewriteArgs(args []string) []string

RewriteArgs is the pre-cobra compatibility shim. It translates:

  • `tile <ref> <action> …` → `tile <action> <ref> …` (legacy id-first form)
  • `-with-key` → `--with-key` (single-dash long the old parser accepted; pflag would read it as bundled shorthands)

It runs on raw argv (without argv[0]) before cobra parses anything.

func WithExitCode

func WithExitCode(code int, err error) error

WithExitCode wraps err so ExitCode reports code.

Types

type Runtime

type Runtime struct {
	Stdin          io.Reader
	Stdout, Stderr io.Writer
	// TTY-ness is checked independently: prompts key off stdin, tables/color
	// off stdout, spinners off stderr.
	StdinTTY, StdoutTTY, StderrTTY bool

	JSON bool // global --json
	Yes  bool // global --yes / -y

	Client func() (*cli.Client, error)
	Link   func() (cli.Link, string, error)
	Getenv func(string) string
}

Runtime carries everything a command touches from its environment, so tests can substitute all of it.

func NewRuntime

func NewRuntime() *Runtime

NewRuntime builds the real-environment runtime.

func (*Runtime) Confirm

func (rt *Runtime) Confirm(title string) error

Confirm gates a destructive action: --yes skips it, a TTY prompts, and a non-TTY stdin refuses rather than proceeding implicitly.

func (*Runtime) EmitError

func (rt *Runtime) EmitError(err error)

EmitError renders err for humans or machines. Used as the fang error handler; the styles are ignored under --json.

func (*Runtime) EmitJSON

func (rt *Runtime) EmitJSON(v any) error

EmitJSON writes v as indented JSON to stdout. nil slices render as [].

func (*Runtime) LinkedStack

func (rt *Runtime) LinkedStack(stackFlag string) (string, error)

LinkedStack resolves the target stack: --stack flag, else the link.

func (*Runtime) PromptSecret

func (rt *Runtime) PromptSecret(title string) (string, error)

PromptSecret reads a secret: masked huh input on a TTY, one plain line from stdin otherwise (so scripts can pipe it in). Accessible mode also reads a plain line, huh's masked accessible input demands a real terminal fd.

func (*Runtime) Table

func (rt *Runtime) Table(headers []string, rows [][]string)

Table renders rows: a headed lipgloss table on a TTY, headerless TSV when piped (matching the old CLI's script-friendly shape).

Jump to

Keyboard shortcuts

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