globals

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package globals provides access to global CLI flags and state. These are set by the root command and can be read by subcommands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyFlags added in v0.16.1

func ApplyFlags(cmd *cobra.Command)

ApplyFlags reads the global CLI flags (--dry-run, --json, --trace) off the invoked command's flag set and applies them to process-wide state.

Cobra runs only the closest PersistentPreRun(E) in the command chain, so a subcommand tree that defines its own hook shadows the root's. Every PersistentPreRun(E) in the CLI must therefore call ApplyFlags first; otherwise the root's persistent flags are silently dropped for that tree and a --dry-run invocation mutates real state. Reading the values off the command's own flag set (persistent flags are inherited and merged at parse time) makes this correct regardless of which hook cobra invokes.

A flag that is not defined on the command is skipped, so ApplyFlags is safe on command trees built without the root's persistent flags.

func DryRun

func DryRun() bool

DryRun returns true if dry-run mode is enabled.

func GHAOutput

func GHAOutput() bool

GHAOutput returns true if GitHub Actions output mode is enabled.

func GuardMutation added in v0.16.1

func GuardMutation(operation string) error

GuardMutation is the dry-run backstop at the lowest boundaries that mutate external state: GitHub API writes (releases, tags, branch protection, the contents API) and git pushes. Every command gates --dry-run explicitly and prints its preview before any of these boundaries is reached, so on a correct dry run this guard is never hit and on a real run it is a no-op.

If a mutation path misses its explicit gate, the guard refuses the operation with a loud error rather than silently mutating (the data-safety failure) or silently skipping (which would hide the missing gate). Callers place it immediately before executing the state-changing request or command, never on read paths.

func JSON

func JSON() bool

JSON returns true if JSON output mode is enabled.

func SetDryRun

func SetDryRun(v bool)

SetDryRun sets the dry-run mode flag.

func SetGHAOutput

func SetGHAOutput(v bool)

SetGHAOutput sets the GitHub Actions output mode flag.

func SetJSON

func SetJSON(v bool)

SetJSON sets the JSON output mode flag.

Types

This section is empty.

Jump to

Keyboard shortcuts

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