root

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package root defines the root configuration for the CLI.

Index

Constants

This section is empty.

Variables

View Source
var ErrUsage = errors.New("invalid usage")

ErrUsage matches any usage error through errors.Is: a missing or malformed argument, an unknown flag or subcommand, conflicting flags. The dispatcher prints the selected command's help only for errors that match ErrUsage (and for --help), so a runtime failure is reported without a screenful of help above it, and main exits 2 for them where other failures exit 1. For the details, recover *UsageError with errors.AsType.

Functions

This section is empty.

Types

type Config

type Config struct {
	Stdin   io.Reader
	Stdout  io.Writer
	Stderr  io.Writer
	Flags   *ff.FlagSet
	Command *ff.Command

	// Options are where the measurement reads its inputs, bound to the
	// flags; their methods (Load, GateInput, ReadBaseline, ...) are the
	// commands' shared shell.
	pipeline.Options
	// Format is "text" or "json".
	Format string
}

Config holds shared I/O writers, the analysis flags every measuring command shares, and the root ff.Command. All subcommand configs embed *Config to inherit these.

func New

func New(stdin io.Reader, stdout, stderr io.Writer) *Config

New returns a new root Config with the given I/O writers.

func (*Config) SARIFOptions

func (cfg *Config) SARIFOptions() sarif.Options

SARIFOptions are what check's SARIF log records besides the result: the tool's version, and the model file relative to --dir.

func (*Config) Write

func (cfg *Config) Write(v any, writeText func(io.Writer) error) error

Write writes v to Stdout: as JSON with --format json, and with writeText otherwise.

func (*Config) WriteReport

func (cfg *Config) WriteReport(r *arch.Report) error

WriteReport writes r to Stdout in the format --format selects.

type ExitError

type ExitError int

ExitError is returned by commands that want a specific non-zero exit code without printing an additional error message. run() in main.go checks for ExitError with errors.As and calls os.Exit(int(e)) directly, bypassing the default "error: ..." printer.

const ErrGateFailed ExitError = 3

ErrGateFailed exits with the status of a check whose gate failed: distinct from 1, a run that could not measure, and 2, a usage error, so CI can tell an architecture regression from a broken pipeline.

func (ExitError) Error

func (e ExitError) Error() string

type UsageError

type UsageError struct {
	Err error
}

UsageError reports that the command line, not the work it asked for, was wrong. Err says what was wrong, e.g. "add: command name required"; its text is the whole message. A command's exec returns one as

return &UsageError{Err: fmt.Errorf("add: --name: %w", err)}

building Err with errors.New or fmt.Errorf, whose %w keeps a cause inspectable.

func (*UsageError) Error

func (e *UsageError) Error() string

func (*UsageError) Is

func (e *UsageError) Is(target error) bool

Is reports whether target is ErrUsage.

func (*UsageError) Unwrap

func (e *UsageError) Unwrap() error

Unwrap returns the cause, so errors.Is and errors.As see through to it.

Jump to

Keyboard shortcuts

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