cli

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package cli defines flow's command tree. One file per command; this file holds the global flags and the per-invocation state every command shares.

Index

Constants

View Source
const (
	ExitOK           = 0
	ExitFailure      = 1
	ExitUsage        = 2
	ExitNotFound     = 3
	ExitPrecondition = 4
	ExitDependency   = 5
	ExitAborted      = 6
)

Exit codes. fang owns the error path, so command handlers never call os.Exit: they return an error, and main maps it through ExitCodeFor.

Variables

View Source
var (
	Version = "dev"
	Commit  = ""
	Date    = ""
)

Build information, stamped by the linker via -ldflags and copied in from main before fang runs, so that `flow --version` and `flow version --json` always report the same values.

Functions

func Aborted

func Aborted(err error) bool

Aborted reports an error that means the user stopped the command themselves, which deserves a one-line acknowledgement rather than a styled error page.

func ErrorAlreadyReported

func ErrorAlreadyReported(err error) bool

ErrorAlreadyReported reports an error whose JSON envelope has already been written to stdout, so the terminal error handler stays silent about it.

func ExitCodeFor

func ExitCodeFor(err error) int

ExitCodeFor maps any error to flow's exit-code scheme.

func KindFor

func KindFor(err error) string

KindFor maps an error to the machine-readable code used in JSON output.

func NewRootCommand

func NewRootCommand() *cobra.Command

NewRootCommand builds the command tree.

func SetBuildInfo

func SetBuildInfo(version, commit, date string)

SetBuildInfo records the linker-stamped values. main calls this before fang.Execute so fang's --version output and flow version agree.

Types

type App

type App struct {
	Out      *output.Renderer
	Runner   flowexec.Runner
	Registry *registry.Store
	// contains filtered or unexported fields
}

App is the state one flow invocation shares across its command. It is built lazily, so that `flow --help` never reads a config file or takes a lock.

func (*App) Config

func (a *App) Config() config.Config

Config returns the effective configuration.

func (*App) ConfigExists

func (a *App) ConfigExists() bool

ConfigExists reports whether a config file was actually read.

func (*App) ConfigPath

func (a *App) ConfigPath() string

ConfigPath returns the resolved config file path, whether or not it exists.

func (*App) DryRun

func (a *App) DryRun() bool

DryRun reports whether mutating actions are suppressed.

func (*App) Editor

func (a *App) Editor() *editor.Launcher

Editor returns the editor launcher.

func (*App) Git

func (a *App) Git(dir string) *gitx.Git

Git returns a git client rooted at dir.

func (*App) GitHub

func (a *App) GitHub(ctx context.Context) *ghapi.Client

GitHub builds the GitHub client, resolving a token from the environment, the config, or the macOS keychain. A missing token is not an error: the returned client reports Unknown for everything it cannot determine.

func (*App) Helm

func (a *App) Helm() *helmx.Helm

Helm returns the helm wrapper used for mutating operations.

func (*App) Herdr

func (a *App) Herdr() *herdr.CLI

Herdr returns the workspace client, or nil when the provider is "none".

func (*App) JSON

func (a *App) JSON() bool

JSON reports whether --json was given.

func (*App) Kube

func (a *App) Kube() *kube.Kube

Kube returns the kubectl wrapper. Everything flow asks kubectl is read-only, so it always uses the unwrapped runner.

func (*App) ReadGit

func (a *App) ReadGit(dir string) *gitx.Git

ReadGit returns a git client that runs even under --dry-run, for inspection.

func (*App) ReadHelm

func (a *App) ReadHelm() *helmx.Helm

ReadHelm returns a helm wrapper for queries, which run even under --dry-run.

func (*App) ReadHerdr

func (a *App) ReadHerdr() *herdr.CLI

ReadHerdr returns a workspace client that runs even under --dry-run.

func (*App) Token

func (a *App) Token(ctx context.Context) (string, secrets.Source)

Token resolves the GitHub token and reports where it came from. The value is never logged; only the source is ever displayed.

func (*App) Yes

func (a *App) Yes() bool

Yes reports whether confirmations are pre-answered.

type Error

type Error struct {
	Code int
	// Kind is the machine-readable code emitted in --json mode.
	Kind string
	Msg  string
	Err  error
}

Error is a flow error carrying the exit code it should produce.

func Dependency

func Dependency(format string, a ...any) *Error

Dependency reports a missing or failing external tool.

func Failure

func Failure(format string, a ...any) *Error

Failure reports a generic error.

func NotFound

func NotFound(format string, a ...any) *Error

NotFound reports an unknown ticket, missing worktree, or absent PR.

func Precondition

func Precondition(format string, a ...any) *Error

Precondition reports a state flow refuses to act on: a dirty worktree, an unmerged PR, the wrong kube context.

func Usage

func Usage(format string, a ...any) *Error

Usage reports a bad flag or argument.

func Wrap

func Wrap(code int, kind string, err error, format string, a ...any) *Error

Wrap attaches an exit code to an existing error.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Jump to

Keyboard shortcuts

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