cli

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 52 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 error `status`/`diff` return under --exit-code. main() maps it to a process exit code and prints nothing (the sentinel's Error() is empty), so a CI gate 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