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

startup

package
v1.233.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package startup holds the configuration-free command startup shared by the root command and by commands that deliberately skip the root pre-run (such as doctor) because they must run on a broken atmos.yaml.

The sequence is split in two phases because the root command loads atmos.yaml between them: flag values must reach Viper before the configuration is loaded, and the I/O context must be built after it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseLogFile

func CloseLogFile()

CloseLogFile flushes and closes the log file opened by Configure. It is safe to call when none is open.

func Configure

func Configure(cmd *cobra.Command) error

Configure runs both startup phases back to back for commands that never load configuration. The order is: refine the color profile from parsed flags, synchronize global flags to Viper, initialize the I/O context, reconcile masking, rebuild the UI and data writers, then configure the logger from --logs-level, --logs-file, and ATMOS_LOGS_*. An unsupported log level or unusable log file is returned as an error with the usage exit code.

func ConfigureEarlyColorProfile

func ConfigureEarlyColorProfile(cmd *cobra.Command)

ConfigureEarlyColorProfile sets the lipgloss color profile based on environment variables and parsed flags. This is called early in the root pre-run, before config loading, to ensure that any theme styles accessed during stack processing respect NO_COLOR and other settings.

func ConfigureLogger

func ConfigureLogger(cmd *cobra.Command) (*os.File, error)

ConfigureLogger applies --logs-level, --logs-file, and their ATMOS_LOGS_* variables without reading atmos.yaml. The returned file handle, when not nil, is the opened log file; the caller owns closing it. An unsupported level is returned as an error with the usage exit code instead of exiting.

func GlobalColorDisabled

func GlobalColorDisabled(config *schema.AtmosConfiguration) bool

GlobalColorDisabled combines configured and early command-line opt-outs before applying forced color.

func InitializeIO

func InitializeIO(cmd *cobra.Command, config *schema.AtmosConfiguration) error

InitializeIO rebuilds the I/O context and the global UI and data writers after flag parsing. This ensures flags like --no-color, --redirect-stderr, --mask are respected. Initialize() sets the global iolib.Data and iolib.UI writers with masking enabled. The loaded configuration, when there is one, supplies the masking literals and patterns.

func InitializeIOOrExit

func InitializeIOOrExit(cmd *cobra.Command, config *schema.AtmosConfiguration)

InitializeIOOrExit is InitializeIO for the root pre-run, where a failure to build the I/O context is fatal.

func LogsConfigFromCommand

func LogsConfigFromCommand(cmd *cobra.Command) schema.Logs

LogsConfigFromCommand builds the minimal logs configuration for commands that never load atmos.yaml. Precedence matches configuration loading: defaults, then ATMOS_LOGS_*, then ATMOS_VERBOSE, then the parsed --logs-level and --logs-file flags, then --verbose.

func PrepareFlags

func PrepareFlags(cmd *cobra.Command)

PrepareFlags applies parsed global flags before anything reads them: the early color profile (--no-color, --force-color, NO_COLOR) and the Viper synchronization of flags that configuration loading depends on. It does not read atmos.yaml.

func ReconcileMasking

func ReconcileMasking(cmd *cobra.Command, config *schema.AtmosConfiguration)

ReconcileMasking applies the configured masking policy and then honors a command-local --mask flag when a subcommand shadows the root flag. Several component command groups register their own persistent common flags; Viper remains bound to the root flag, so the changed local value must win. A nil config skips registering configured literals and patterns.

func SetupLogger

func SetupLogger(atmosConfig *schema.AtmosConfiguration) (*os.File, error)

SetupLogger configures the global logger based on the provided Atmos configuration. It returns the opened log file when the configuration names a regular file, so the caller can close it on shutdown, and an error when the log file cannot be opened or the log level is unsupported.

func SyncGlobalFlagsToViper

func SyncGlobalFlagsToViper(cmd *cobra.Command)

SyncGlobalFlagsToViper synchronizes global flags from Cobra's FlagSet to Viper. This is necessary because Viper's BindPFlag doesn't immediately sync values when flags are parsed. Call this after Cobra parses flags but before accessing flag values via Viper.

Background: When using viper.BindPFlag(), the binding happens at initialization time, but the actual flag value isn't synced to Viper until you call viper.Get*(). For some code paths (especially in InitCliConfig), we need the flag values available in Viper before config loading completes.

This function explicitly syncs changed flags to Viper, making their values immediately available via viper.Get*() calls.

Types

This section is empty.

Jump to

Keyboard shortcuts

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