root

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 29 Imported by: 0

README

Root Command

The entry point and orchestration layer for GTB CLI applications.

Key Responsibilities:

  • Persistent service initialization (Logging, Configuration)
  • Global flag management (--config, --debug, --ci)
  • Lifecycle hooks (PersistentPreRunE)
  • Automatic feature command registration

For detailed documentation on the root command and the application lifecycle, see the Built-in Commands Documentation.

Documentation

Overview

Package root provides the reusable root Cobra command constructor that wires configuration loading, logging setup, update checks, and feature-flagged subcommand registration (version, update, init, docs, MCP).

The NewCmdRoot and NewCmdRootWithConfig functions build a root command whose PersistentPreRunE handles config merging (local files + embedded assets), log level/format configuration, and optional self-update prompting before any subcommand executes.

Index

Constants

This section is empty.

Variables

View Source
var ErrUpdateComplete = errors.New("update complete — restart required")

ErrUpdateComplete is returned by PersistentPreRunE when a self-update has completed successfully. The Execute wrapper handles this by exiting cleanly without logging an error.

Functions

func Execute

func Execute(rootCmd *cobra.Command, props *p.Props)

Execute runs the root command with centralized error handling. It silences Cobra's default error output and routes any error returned by the command tree through ErrorHandler.Check at Fatal level.

func NewCmdRoot

func NewCmdRoot(props *p.Props, subcommands ...*cobra.Command) *cobra.Command

NewCmdRoot creates the root command with Props wiring and optional subcommands.

func NewCmdRootWithConfig

func NewCmdRootWithConfig(props *p.Props, configPaths []string, subcommands ...*cobra.Command) *cobra.Command

NewCmdRootWithConfig creates the root command for the CLI application. It accepts additional configuration file paths to be considered during initialization. NewCmdRoot creates the root command with Props wiring and optional subcommands.

Types

type ConfigLoadOptions

type ConfigLoadOptions struct {
	CfgPaths    []string
	ConfigPaths []string
	Props       *p.Props
	AllowEmpty  bool
}

ConfigLoadOptions holds the options needed for loading configuration.

type FlagValues

type FlagValues struct {
	CI    bool
	Debug bool
}

FlagValues holds the command-line flag values extracted from cobra command.

type OutdatedVersionOption

type OutdatedVersionOption func(*outdatedVersionConfig)

OutdatedVersionOption configures handleOutdatedVersion behavior.

func WithForm

func WithForm(formCreator func(*bool) *huh.Form) OutdatedVersionOption

WithForm allows providing a custom form creator for testing.

type UpdateCheckResult

type UpdateCheckResult struct {
	HasUpdated bool
	ShouldExit bool
	Error      error
}

UpdateCheckResult holds the result of checking for updates.

Jump to

Keyboard shortcuts

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