common

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const KeyRequireGlobalChecks = "requireGlobalChecks"

Variables

This section is empty.

Functions

func CheckWorkflowReport added in v0.12.0

func CheckWorkflowReport(ctx context.Context, report *automa.Report)

CheckWorkflowReport checks for errors, saves the YAML report, and prints a compact summary. Exported for commands that handle reports outside RunWorkflow (e.g. block node install/upgrade/reset).

func DefaultRunE

func DefaultRunE(cmd *cobra.Command, args []string) error

DefaultRunE is a default RunE function that shows help message and provides a placeholder to add common behaviour. We always add a run function to commands to ensure cobra marks it as Runnable and allows our commands to invoke PersistentPreRunE functions of the root command.

func DetectShortNameCollisions added in v0.12.0

func DetectShortNameCollisions(root *cobra.Command) bool

func ExtractRootFlags added in v0.12.0

func ExtractRootFlags(cmd *cobra.Command, args []string, flags *RootFlags) error

ExtractRootFlags extracts the flags registered on the root command. Config and logging are already initialized by root.go's initConfig (via cobra.OnInitialize).

func GetExecutionMode added in v0.7.0

func GetExecutionMode(continueOnErr bool, stopOnErr bool, rollbackOnErr bool) (automa.TypeMode, error)

GetExecutionMode determines the execution mode based on the provided flags. It ensures that only one of the flags is set; otherwise, it returns an error. The precedence is as follows: 1. continueOnErr 2. rollbackOnErr 3. stopOnErr (default)

func RequireGlobalChecks

func RequireGlobalChecks(cmd *cobra.Command) bool

RequireGlobalChecks checks if a command requires global pre-run checks. By default, commands require global checks unless explicitly marked to skip them.

func RunPersistentPreRun added in v0.16.0

func RunPersistentPreRun(cmd *cobra.Command, args []string) error

RunPersistentPreRun is the body of the root PersistentPreRunE hook. It runs before every command and is responsible for:

  1. Verifying the weaver installation (skipped for commands that opt out via SkipGlobalChecks).
  2. Running any pending startup migrations.

func RunStartupMigrations added in v0.14.0

func RunStartupMigrations(ctx context.Context) error

RunStartupMigrations runs a single ordered pass over all startup-scoped migrations. It is a no-op when no migrations apply.

func RunWorkflow

func RunWorkflow(ctx context.Context, fn func() (*automa.Report, error))

RunWorkflow executes a workflow function and renders progress via Bubble Tea with spinners and status icons, or raw zerolog output when --non-interactive is set.

func RunWorkflowBuilder added in v0.15.0

func RunWorkflowBuilder(ctx context.Context, b automa.Builder)

RunWorkflowBuilder is a convenience wrapper that builds an automa workflow and runs it via RunWorkflow.

func SkipGlobalChecks

func SkipGlobalChecks(cmd *cobra.Command)

SkipGlobalChecks marks a command to skip global pre-run checks. This is useful for commands like 'install' that need to run before any checks can be performed. It sets the annotation "requireGlobalChecks" to "false".

Types

type CountFlagDefinition added in v0.16.0

type CountFlagDefinition struct {
	Name        string
	ShortName   string
	Description string
}

CountFlagDefinition defines a count-style persistent flag (e.g. -V -V → 2). It is separate from FlagDefinition[int] because pflag registers count flags with type "count" and requires CountVarP/GetCount rather than IntVarP/GetInt.

func FlagVerbose added in v0.16.0

func FlagVerbose() CountFlagDefinition

func (CountFlagDefinition) SetVarP added in v0.16.0

func (f CountFlagDefinition) SetVarP(cmd *cobra.Command, p *int)

SetVarP registers the flag as a persistent count flag on the given command.

func (CountFlagDefinition) Value added in v0.16.0

func (f CountFlagDefinition) Value(cmd *cobra.Command, args []string) (int, error)

Value reads the current count value from the command's merged flag set.

type FlagDefinition added in v0.7.0

type FlagDefinition[T any] struct {
	Name        string
	ShortName   string
	Description string
	Default     T
}

FlagDefinition defines a command-line flag typed by T.

func FlagConfig added in v0.12.0

func FlagConfig() FlagDefinition[string]

func FlagContinueOnError added in v0.7.0

func FlagContinueOnError() FlagDefinition[bool]

func FlagForce added in v0.12.0

func FlagForce() FlagDefinition[bool]

func FlagLogLevel added in v0.12.0

func FlagLogLevel() FlagDefinition[string]

func FlagMetricsServer added in v0.7.0

func FlagMetricsServer() FlagDefinition[bool]

func FlagNoReuseValues added in v0.12.0

func FlagNoReuseValues() FlagDefinition[bool]

func FlagNodeType added in v0.7.0

func FlagNodeType() FlagDefinition[string]

func FlagNonInteractive added in v0.16.0

func FlagNonInteractive() FlagDefinition[bool]

func FlagOutputFormat added in v0.12.0

func FlagOutputFormat() FlagDefinition[string]

func FlagProfile added in v0.7.0

func FlagProfile() FlagDefinition[string]

func FlagRollbackOnError added in v0.7.0

func FlagRollbackOnError() FlagDefinition[bool]

func FlagSkipHardwareChecks added in v0.9.0

func FlagSkipHardwareChecks() FlagDefinition[bool]

FlagSkipHardwareChecks is a hidden persistent flag registered on the root command. When set, it skips CPU, memory, and storage validation in NewNodeSafetyCheckWorkflow (see internal/workflows/preflight.go). Privilege, user, and host profile checks still run. This flag is intentionally not supported by the "check" command since its purpose is to validate hardware requirements.

Used by: block node install, kube cluster install. Registered in: cmd/weaver/commands/root.go (hidden). See docs/dev/hidden-flags.md for full documentation.

func FlagStopOnError added in v0.7.0

func FlagStopOnError() FlagDefinition[bool]

func FlagValuesFile added in v0.7.0

func FlagValuesFile() FlagDefinition[string]

func FlagVersion added in v0.12.0

func FlagVersion() FlagDefinition[bool]

func FlagWithStorageReset added in v0.12.0

func FlagWithStorageReset() FlagDefinition[bool]

func (FlagDefinition[T]) Clone added in v0.12.0

func (fp FlagDefinition[T]) Clone() FlagDefinition[T]

Clone returns an independent copy of the descriptor. Useful when you need a local variant with a different default or description.

func (FlagDefinition[T]) MarkRequired added in v0.7.0

func (fp FlagDefinition[T]) MarkRequired(cmd *cobra.Command, v bool) error

func (FlagDefinition[T]) MarkRequiredP added in v0.7.0

func (fp FlagDefinition[T]) MarkRequiredP(cmd *cobra.Command, v bool) error

func (FlagDefinition[T]) SetVar added in v0.7.0

func (fp FlagDefinition[T]) SetVar(cmd *cobra.Command, p *T, required bool)

SetVar sets up the non-persistent flag and exits on error.

func (FlagDefinition[T]) SetVarP added in v0.7.0

func (fp FlagDefinition[T]) SetVarP(cmd *cobra.Command, p *T, required bool)

SetVarP sets up the persistent flag and exits on error.

func (FlagDefinition[T]) Value added in v0.7.0

func (fp FlagDefinition[T]) Value(cmd *cobra.Command, args []string) (T, error)

Value resolves a flag value using the following precedence:

  1. Local (non-persistent) flags on this command
  2. Own persistent flags on this command (defined via SetVarP on this command directly)
  3. Persistent flags inherited from parent/root commands (merged by Cobra via ParseFlags)

Use ValueLocal() or ValueOwnPersistent() if you need strict single-scope semantics.

func (FlagDefinition[T]) ValueLocal added in v0.12.0

func (fp FlagDefinition[T]) ValueLocal(cmd *cobra.Command, args []string) (T, error)

func (FlagDefinition[T]) ValueOwnPersistent added in v0.12.0

func (fp FlagDefinition[T]) ValueOwnPersistent(cmd *cobra.Command, args []string) (T, error)

ValueOwnPersistent reads the value of a persistent flag defined directly on this command (via SetVarP). It does NOT search ancestor/parent commands.

Use Value() if you want the full resolution chain (local → own persistent → inherited persistent). Use ValueLocal() if you want only local (non-persistent) flags on this command.

type RootFlags added in v0.12.0

type RootFlags struct {
	Config             string
	Force              bool
	SkipHardwareChecks bool
	LogLevel           string
}

RootFlags contains the flags registered on the root command and available to every subcommand via persistent inheritance.

type SetupResult added in v0.16.0

type SetupResult struct {
	Config         models.Config
	StateManager   state.Manager
	RealityChecker reality.Checkers
	Runtime        *rsl.RuntimeResolver
}

func Setup added in v0.16.0

func Setup() (*SetupResult, error)

Setup performs the common setup steps for all commands. It includes loading configuration, initializing the state manager, reality checker and runtime resolver

Jump to

Keyboard shortcuts

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