Help us shape the future of Go! Take the 2026 Go Developer Survey

cli

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 55 Imported by: 0

Documentation

Overview

Package cli wires cobra subcommands. NewRoot returns the root *cobra.Command with all subcommands attached.

Index

Constants

View Source
const NoUpgradeNoticeEnv = "AGENTSYNC_NO_UPGRADE_NOTICE"

NoUpgradeNoticeEnv opts a machine out of the first-run-after-upgrade notice entirely: nothing is printed and nothing is recorded, so unsetting it shows any still-unseen notice rather than swallowing it permanently.

Variables

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

version metadata; main.go injects via -ldflags. Tests use the literal strings below.

Functions

func Execute

func Execute() int

Execute builds and runs the command tree and returns the PROCESS EXIT CODE. main.go is the only caller: `os.Exit(cli.Execute())`.

Owning the whole invocation — build, run, report, exit code — is what lets the terminal error be styled with no package-level state: `root` is still in scope after it returns, so colorModeOf reads the parsed `--color` flag directly rather than a package var carrying it across the main boundary.

Two cobra details make that safe. One `*pflag.Flag` is shared between root and subcommands, so `colorModeOf(root)` sees a value parsed on a SUBCOMMAND's line. And when cobra fails before parsing flags (unknown subcommand, malformed flag) the value is unset and this yields ColorAuto — which is also why `mode, _` discards ParseColorMode's error: it returns ColorAuto alongside it.

func NewRoot

func NewRoot() *cobra.Command

NewRoot constructs the root command tree. Tests build their own root via this constructor so flag state is isolated per test.

Types

type ExitCoder added in v0.11.0

type ExitCoder interface{ ExitCode() int }

ExitCoder is implemented by the quiet sentinel errors that carry their OWN process exit code: `status`/`diff` under --exit-code (exitCodeDrift), and `secret edit`'s interrupt sentinel (exitCodeInterrupted). main() maps it to that code and prints NOTHING — reportErrorTo returns on the ExitCoder branch before any formatting, so the sentinel's message never reaches the user whether it is empty or not. A CI gate therefore gets a stable non-zero exit without a spurious "agentsync: ..." line. The root command already sets SilenceErrors, so cobra prints nothing for it either.

Jump to

Keyboard shortcuts

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