base

package
v0.267.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package base provides the root `ofga` command: persistent flags, the help banner, and registration of every top-level sub-command.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstUnknownFlag

func FirstUnknownFlag(cmd *cobra.Command, args []string) string

applyEnvironment resolves the color profile, theme, and output toggles from flags, environment (NO_COLOR, FORCE_COLOR, TERM=dumb) and config. FirstUnknownFlag returns the first token in args that looks like a flag but is not defined on cmd's flag set (long name or shorthand), or "" if none. Used only on the error path to disambiguate pflag swallowing an unknown flag's following token as its value (a mistyped global flag before a subcommand path otherwise surfaces as a misleading "unknown command").

Scanning stops at the first positional (non-flag) token: that positional is the intended command path, so any flag after it belongs to the (possibly mistyped) subcommand, not the root, and must not override cobra's own "unknown command" diagnosis. Known flags that take a separate value token consume that token so it isn't mistaken for the command positional.

func ForceColor

func ForceColor() bool

ForceColor and ForceMono interpret the documented FORCE_COLOR variable, which colorprofile's writers ignore (they honor only CLICOLOR_FORCE). Following the widely-adopted convention (npm/chalk/supports-color), FORCE_COLOR=0/false/no/off disables color and any other non-empty value forces it on; unset is no opinion. ForceColor reports whether color is explicitly forced on.

func ForceMono

func ForceMono() bool

ForceMono reports whether color is explicitly forced off.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command is the root command.

func New

func New(cli *cli.CLI) *Command

New constructs the root command and wires persistent flags + sub-commands.

func (*Command) Command

func (c *Command) Command() *cobra.Command

Command returns the root cobra command.

func (*Command) ErrWriter

func (c *Command) ErrWriter() *colorprofile.Writer

ErrWriter returns the profile-aware writer wrapping stderr, so callers outside cobra's own output path (e.g. main's final error print) can reuse the same NO_COLOR/pipe-aware downsampling.

func (*Command) RanCommand

func (c *Command) RanCommand() bool

RanCommand reports whether execution reached PersistentPreRunE, i.e. flag and argument validation passed. When it is false after Execute returns an error, the failure was a bad invocation and main exits with CodeUsage.

func (*Command) RegisterSubCommands

func (c *Command) RegisterSubCommands()

RegisterSubCommands adds all top-level commands.

Jump to

Keyboard shortcuts

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