cmdutil

package
v0.0.0-...-afecb3f Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package cmdutil holds functionality to run titan via cobra. That includes flag parsing and configuration of components common to all subcommands

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CmdBase

type CmdBase struct {
	UI           cli.Ui
	Logger       hclog.Logger
	RepoRoot     titanpath.AbsoluteSystemPath
	APIClient    *client.ApiClient
	RepoConfig   *config.RepoConfig
	UserConfig   *config.UserConfig
	RemoteConfig client.RemoteConfig
	TurboVersion string
}

CmdBase encompasses configured components common to all titan commands.

func (*CmdBase) LogError

func (b *CmdBase) LogError(format string, args ...interface{})

LogError prints an error to the UI

func (*CmdBase) LogInfo

func (b *CmdBase) LogInfo(msg string)

LogInfo logs an message and outputs it to the UI.

func (*CmdBase) LogWarning

func (b *CmdBase) LogWarning(prefix string, err error)

LogWarning logs an error and outputs it to the UI.

type Helper

type Helper struct {
	// TurboVersion is the version of titan that is currently executing
	TurboVersion string

	// UserConfigPath is the path to where we expect to find
	// a user-specific config file, if one is present. Public
	// to allow overrides in tests
	UserConfigPath titanpath.AbsoluteSystemPath
	// contains filtered or unexported fields
}

Helper is a struct used to hold configuration values passed via flag, env vars, config files, etc. It is not intended for direct use by titan commands, it drives the creation of CmdBase, which is then used by the commands themselves.

func NewHelper

func NewHelper(titanVersion string) *Helper

NewHelper returns a new helper instance to hold configuration values for the root titan command.

func (*Helper) AddFlags

func (h *Helper) AddFlags(flags *pflag.FlagSet)

AddFlags adds common flags for all titan commands to the given flagset and binds them to this instance of Helper

func (*Helper) Cleanup

func (h *Helper) Cleanup(flags *pflag.FlagSet)

Cleanup runs the register cleanup handlers. It requires the flags to the root command so that it can construct a UI if necessary

func (*Helper) GetCmdBase

func (h *Helper) GetCmdBase(flags *pflag.FlagSet) (*CmdBase, error)

GetCmdBase returns a CmdBase instance configured with values from this helper. It additionally returns a mechanism to set an error, so

func (*Helper) RegisterCleanup

func (h *Helper) RegisterCleanup(cleanup io.Closer)

RegisterCleanup saves a function to be run after titan execution, even if the command that runs returns an error

Jump to

Keyboard shortcuts

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