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 ¶
- Variables
- func Execute() int
- func ExitCode(err error) int
- func NewRoot(rt *Runtime) *cobra.Command
- func RewriteArgs(args []string) []string
- func WithExitCode(code int, err error) error
- type Runtime
- func (rt *Runtime) Confirm(title string) error
- func (rt *Runtime) EmitError(err error)
- func (rt *Runtime) EmitJSON(v any) error
- func (rt *Runtime) LinkedStack(stackFlag string) (string, error)
- func (rt *Runtime) PromptSecret(title string) (string, error)
- func (rt *Runtime) Table(headers []string, rows [][]string)
Constants ¶
This section is empty.
Variables ¶
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 RewriteArgs ¶
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 ¶
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 (*Runtime) Confirm ¶
Confirm gates a destructive action: --yes skips it, a TTY prompts, and a non-TTY stdin refuses rather than proceeding implicitly.
func (*Runtime) EmitError ¶
EmitError renders err for humans or machines. Used as the fang error handler; the styles are ignored under --json.
func (*Runtime) LinkedStack ¶
LinkedStack resolves the target stack: --stack flag, else the link.
func (*Runtime) PromptSecret ¶
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.