tui

package
v0.14.5 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: MPL-2.0 Imports: 61 Imported by: 0

Documentation

Overview

Package tui provides the Terminal User Interface (TUI) of the CLI.

Index

Constants

View Source
const ErrSetup errors.Kind = "failed to setup Terramate"

ErrSetup is the error returned when the CLI fails to setup its initial values.

View Source
const KongContext contextStr = "kong.context"

KongContext is the context key for the Kong context.

View Source
const KongError contextStr = "kong.error"

KongError is the context key for the Kong error.

Variables

This section is empty.

Functions

func ConfigureLogging

func ConfigureLogging(logLevel, logFmt, logdest string, stdout, stderr io.Writer) error

ConfigureLogging configures Terramate global logging.

func DefaultAfterConfigHandler

func DefaultAfterConfigHandler(ctx context.Context, c *CLI) (commands.Executor, bool, bool, error)

DefaultAfterConfigHandler implements the default flags handling for when the config is already parsed. Use WithSpecHandler if you need a different behavior.

func DefaultBeforeConfigHandler

func DefaultBeforeConfigHandler(ctx context.Context, c *CLI) (cmd commands.Executor, found bool, cont bool, err error)

DefaultBeforeConfigHandler implements the default flags handling for when the config is not yet parsed. Use WithSpecHandler if you need a different behavior.

Types

type CLI

type CLI struct {
	// contains filtered or unexported fields
}

CLI is the Terramate command-line interface opaque type. The default flag spec is [input.Spec] and handler is DefaultAfterConfigHandler.

func NewCLI

func NewCLI(opts ...Option) (*CLI, error)

NewCLI creates a new CLI instance. The opts options modify the default CLI behavior.

func (*CLI) Config

func (c *CLI) Config() *config.Root

Config returns the CLI Terramate configuration.

func (*CLI) DidKongExit

func (c *CLI) DidKongExit() bool

DidKongExit returns true if Kong intends to exit.

func (*CLI) Engine

func (c *CLI) Engine() *engine.Engine

Engine returns the CLI Terramate engine.

func (*CLI) Exec

func (c *CLI) Exec(args []string)

Exec executes the CLI with the given arguments.

func (*CLI) InitAnalytics

func (c *CLI) InitAnalytics(cmd string, opts ...tel.MessageOpt)

InitAnalytics initializes the analytics record.

func (*CLI) InputSpec

func (c *CLI) InputSpec() any

InputSpec returns the CLI flags spec.

func (*CLI) Printers

func (c *CLI) Printers() printer.Printers

Printers returns the CLI printers.

func (*CLI) Version

func (c *CLI) Version() string

Version returns the CLI Terramate version.

func (*CLI) WorkingDir

func (c *CLI) WorkingDir() string

WorkingDir returns the CLI working directory.

type FlagSpec

type FlagSpec struct {
	DisableCheckpoint          bool `hidden:"true" optional:"true" default:"false" help:"Disable checkpoint checks for updates."`
	DisableCheckpointSignature bool `hidden:"true" optional:"true" default:"false" help:"Disable checkpoint signature."`
	CPUProfiling               bool `hidden:"true" optional:"true" default:"false" help:"Create a CPU profile file when running"`

	Create struct {
		Path        string   `arg:"" optional:"" name:"path" predictor:"file" help:"Path of the new stack."`
		ID          string   `help:"Set the ID of the stack, defaults to an UUIDv4 string."`
		Name        string   `help:"Set the name of the stack, defaults to the basename of <path>"`
		Description string   `help:"Set the description of the stack, defaults to <name>"`
		Import      []string `help:"Add 'import' block to the configuration of the new stack."`
		After       []string `help:"Add 'after' attribute to the configuration of the new stack."`
		Before      []string `help:"Add 'before' attribute to the configuration of the new stack."`
		Wants       []string `help:"Add 'wants' attribute to the configuration of the new stack."`
		WantedBy    []string `help:"Add 'wanted_by' attribute to the configuration of the new stack."`

		Watch          []string `help:"Add 'watch' attribute to the configuration of the new stack."`
		IgnoreExisting bool     `help:"Skip creation without error when the stack already exist."`
		AllTerraform   bool     `help:"Import existing Terraform Root Modules as stacks."`
		AllTerragrunt  bool     `help:"Import existing Terragrunt Modules as stacks."`
		EnsureStackIDs bool     `name:"ensure-stack-ids" help:"Set the ID of existing stacks that do not set an ID to a new UUIDv4."`
		NoGenerate     bool     `help:"Do not run code generation after creating the new stack."`
	} `cmd:"" help:"Create or import stacks."`

	Fmt struct {
		Files            []string `arg:"" optional:"true" predictor:"file" help:"List of files to be formatted."`
		Check            bool     `hidden:"" help:"Lists unformatted files but do not change them. (Exits with 0 if all is formatted, 1 otherwise)"`
		DetailedExitCode bool     `help:"Return a detailed exit code: 0 nothing changed, 1 an error happened, 2 changes were made."`
	} `cmd:"" help:"Format configuration files."`

	List struct {
		Why bool `help:"Shows the reason why the stack has changed."`

		Target   string `help:"Select the deployment target of the filtered stacks."`
		RunOrder bool   `default:"false" help:"Sort listed stacks by order of execution"`
		// contains filtered or unexported fields
	} `cmd:"" help:"List stacks."`

	Run struct {
		// contains filtered or unexported fields
	} `cmd:"" help:"Run command in the stacks"`

	Generate struct {
		Parallel         int  `env:"TM_ARG_GENERATE_PARALLEL" short:"j" optional:"true" help:"Set the parallelism of code generation"`
		DetailedExitCode bool `default:"false" help:"Return a detailed exit code: 0 nothing changed, 1 an error happened, 2 changes were made."`
	} `cmd:"" help:"Run Code Generation in stacks."`

	Script struct {
		List struct{} `cmd:"" help:"List scripts."`
		Tree struct{} `cmd:"" help:"Dump a tree of scripts."`
		Info struct {
			Cmds []string `arg:"" optional:"true" passthrough:"" help:"Script to show info for."`
		} `cmd:"" help:"Show detailed information about a script"`
		Run struct {
			// contains filtered or unexported fields
		} `cmd:"" help:"Run a Terramate Script in stacks."`
	} `cmd:"" help:"Use Terramate Scripts"`

	Debug struct {
		Show struct {
			Metadata        struct{} `cmd:"" help:"Show metadata available in stacks."`
			Globals         struct{} `cmd:"" help:"Show globals available in stacks."`
			GenerateOrigins struct {
			} `cmd:"" help:"Show details about generated code in stacks."`
			RuntimeEnv struct{} `cmd:"" help:"Show available run-time environment variables (ENV) in stacks."`
		} `cmd:"" help:"Show configuration details of stacks."`
	} `cmd:"" help:"Debug Terramate configuration."`

	Cloud struct {
		Login struct {
			Google bool `optional:"true" help:"authenticate with google credentials"`
			Github bool `optional:"true" help:"authenticate with github credentials"`
			SSO    bool `optional:"true" help:"authenticate with SSO credentials"`
		} `cmd:"" help:"Sign in to Terramate Cloud."`
		Info  struct{} `cmd:"" help:"Show your current Terramate Cloud login status."`
		Drift struct {
			Show struct {
				Target string `help:"Show stacks from the given deployment target."`
			} `cmd:"" help:"Show the current drift of a stack."`
		} `cmd:"" help:"Interact with Terramate Cloud Drift Detection."`
	} `cmd:"" help:"Interact with Terramate Cloud"`

	Trigger struct {
		Stack        string `arg:"" optional:"true" name:"stack" predictor:"file" help:"The stacks path."`
		Recursive    bool   `default:"false" help:"Recursively triggers all child stacks of the given path"`
		Change       bool   `default:"false" help:"Trigger stacks as changed"`
		IgnoreChange bool   `default:"false" help:"Trigger stacks to be ignored by change detection"`
		Reason       string `default:"" name:"reason" help:"Set a reason for triggering the stack."`
		// contains filtered or unexported fields
	} `cmd:"" hidden:""  help:"Mark a stack as changed so it will be triggered in Change Detection. (DEPRECATED)"`

	Experimental struct {
		Clone struct {
			SrcDir          string `arg:"" name:"srcdir" predictor:"file" help:"Path of the stack being cloned."`
			DestDir         string `arg:"" name:"destdir" predictor:"file" help:"Path of the new stack."`
			SkipChildStacks bool   `default:"false" help:"Do not clone nested child stacks."`
			NoGenerate      bool   `help:"Do not run code generation after cloning the stacks."`
		} `cmd:"" help:"Clone a stack."`

		Trigger struct {
			Stack        string `arg:"" optional:"true" name:"stack" predictor:"file" help:"The stacks path."`
			Recursive    bool   `default:"false" help:"Recursively triggers all child stacks of the given path"`
			Change       bool   `default:"false" help:"Trigger stacks as changed"`
			IgnoreChange bool   `default:"false" help:"Trigger stacks to be ignored by change detection"`
			Reason       string `default:"" name:"reason" help:"Set a reason for triggering the stack."`
			// contains filtered or unexported fields
		} `cmd:"" hidden:"" help:"Mark a stack as changed so it will be triggered in Change Detection. (DEPRECATED)"`

		RunGraph struct {
			Outfile string `short:"o" predictor:"file" default:"" help:"Output .dot file"`
			Label   string `short:"l" default:"stack.name" help:"Label used in graph nodes (it could be either \"stack.name\" or \"stack.dir\""`
		} `cmd:"" help:"Generate a graph of the execution order"`

		Vendor struct {
			Download struct {
				Dir       string `short:"d" predictor:"file" default:"" help:"dir to vendor downloaded project"`
				Source    string `arg:"" name:"source" help:"Terraform module source URL, must be Git/Github and should not contain a reference"`
				Reference string `arg:"" name:"ref" help:"Reference of the Terraform module to vendor"`
			} `cmd:"" help:"Downloads a Terraform module and stores it on the project vendor dir"`
		} `cmd:"" help:"Manages vendored Terraform modules"`

		Eval struct {
			Global map[string]string `short:"g" help:"set/override globals. eg.: --global name=<expr>"`
			AsJSON bool              `help:"Outputs the result as a JSON value"`
			Exprs  []string          `arg:"" help:"expressions to be evaluated" name:"expr" passthrough:""`
		} `cmd:"" help:"Eval expression"`

		PartialEval struct {
			Global map[string]string `short:"g" help:"set/override globals. eg.: --global name=<expr>"`
			Exprs  []string          `arg:"" help:"expressions to be partially evaluated" name:"expr" passthrough:""`
		} `cmd:"" help:"Partial evaluate the expressions"`

		GetConfigValue struct {
			Global map[string]string `short:"g" help:"set/override globals. eg.: --global name=<expr>"`
			AsJSON bool              `help:"Outputs the result as a JSON value"`
			Vars   []string          `arg:"" help:"variable to be retrieved" name:"var" passthrough:""`
		} `cmd:"" help:"Get configuration value"`

		Cloud struct {
			Login struct{} `cmd:"" help:"login for cloud.terramate.io  (DEPRECATED)"`
			Info  struct{} `cmd:"" help:"cloud information status (DEPRECATED)"`
			Drift struct {
				Show struct {
				} `cmd:"" help:"show drifts  (DEPRECATED)"`
			} `cmd:"" help:"manage cloud drifts  (DEPRECATED)"`
		} `cmd:"" hidden:"" help:"Terramate Cloud commands (DEPRECATED)"`
	} `cmd:"" help:"Use experimental features."`

	InstallCompletions kongplete.InstallCompletions `cmd:"" help:"Install shell completions."`

	Version struct{} `cmd:"" help:"Show Terramate version"`
	// contains filtered or unexported fields
}

FlagSpec defines the default Terramate flags and commands.

type Handler

type Handler func(ctx context.Context, c *CLI) (commands.Executor, bool, bool, error)

Handler is a function that handles the CLI configuration.

type Option

type Option func(*CLI) error

Option is a function that modifies the CLI behavior.

func WithCompactHelp

func WithCompactHelp(b bool) Option

WithCompactHelp is an option to modify the helper compact option.

func WithDescription

func WithDescription(desc string) Option

WithDescription is an option to modify the project description.

func WithExpandSubcommandsInHelp

func WithExpandSubcommandsInHelp() Option

WithExpandSubcommandsInHelp is an option to expand the subcommands in the help. By default they are not shown.

func WithHCLOptions

func WithHCLOptions(hclOpts ...hcl.Option) Option

WithHCLOptions is an option to set the HCL options for the CLI.

func WithHelpPrinter

func WithHelpPrinter(p kong.HelpPrinter) Option

WithHelpPrinter allows for customizing the help output.

func WithName

func WithName(name string) Option

WithName is an option modify the project name.

func WithSpecHandler

func WithSpecHandler(a any, beforeHandler, afterHandler Handler, checkers ...RootFlagHandlers) Option

WithSpecHandler is an option to set the flag spec and handler for the CLI.

func WithStderr

func WithStderr(w io.Writer) Option

WithStderr is an option to modify the CLI stderr channel.

func WithStdin

func WithStdin(r io.Reader) Option

WithStdin is an option to modify the CLI stdin channel.

func WithStdout

func WithStdout(w io.Writer) Option

WithStdout is an option to modify the CLI stdout channel.

func WithVersion

func WithVersion(v string) Option

WithVersion is an option to modify the CLI version. Default is `terramate.Version()`.

type RootFlagHandlers

type RootFlagHandlers func(parsed any, cli *CLI) (name string, val any, run func(c *CLI, value any) error, isset bool)

RootFlagHandlers is a function signature for root flag handlers.

func DefaultRootFlagHandlers

func DefaultRootFlagHandlers() []RootFlagHandlers

DefaultRootFlagHandlers returns the CLI default flag handlers for global flags that can be used alone (without a command). For example: terramate --version

Directories

Path Synopsis
Package cliauth provides the helper functions for loading the Terramate Cloud credentials.
Package cliauth provides the helper functions for loading the Terramate Cloud credentials.
Package cliconfig implements the parser and load of Terramate CLI Configuration files (.terramaterc and terramate.rc).
Package cliconfig implements the parser and load of Terramate CLI Configuration files (.terramaterc and terramate.rc).
Package clitest provides constants and errors kind reused by the cli implementation and the e2e test infrastructure.
Package clitest provides constants and errors kind reused by the cli implementation and the e2e test infrastructure.
Package out provides output functionality, including verboseness level and normal/error messages support.
Package out provides output functionality, including verboseness level and normal/error messages support.
Package telemetry provides types and helpers for CLI telemetry.
Package telemetry provides types and helpers for CLI telemetry.

Jump to

Keyboard shortcuts

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