cmdutil

package
v3.114.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 39 Imported by: 106

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultASCIISpinFrames is the default set of symbols to show while spinning in an ASCII TTY setting.
	DefaultASCIISpinFrames = []string{
		"|", "/", "-", "\\",
	}
	// DefaultEmojiSpinFrames is the default set of symbols to show while spinning in a Unicode-enabled TTY setting.
	DefaultEmojiSpinFrames = []string{
		"⠋", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋",
	}
)
View Source
var DisableInteractive bool

DisableInteractive may be set to true in order to disable prompts. This is useful when running in a non-attended scenario, such as in continuous integration, or when using the Pulumi CLI/SDK in a programmatic way.

View Source
var Emoji = (runtime.GOOS == "darwin")

Emoji controls whether emojis will by default be printed in the output. While some Linux systems can display Emoji's in the terminal by default, we restrict this to just macOS, like Yarn.

View Source
var FullyQualifyStackNames bool

If true, we'll always print fully-qualified stack names (of the form organisation/project/stack. Defaults to false. Can be set by passing --fully-qualify-stack-names or -Q at the command line.

NoArgs is the same as cobra.NoArgs, except it is wrapped with ArgsFunc to provide standard Pulumi error handling.

View Source
var TracingEndpoint string

TracingEndpoint is the Zipkin-compatible tracing endpoint where tracing data will be sent.

View Source
var TracingRootSpan opentracing.Span
View Source
var TracingToFile bool

TracingToFile indicates if pulumi was called with a file:// scheme URL (--tracing=file:///...).

Deprecated: Even in this case TracingEndpoint will now have the tcp:// scheme and will point to a proxy server that will append traces to the user-specified file. Plugins should respect TracingEndpoint and ignore TracingToFile.

Functions

func ArgsFunc

func ArgsFunc(argsValidator cobra.PositionalArgs) cobra.PositionalArgs

ArgsFunc wraps a standard cobra argument validator with standard Pulumi error handling.

func CloseProfiling

func CloseProfiling(prefix string) error

func CloseTracing

func CloseTracing()

CloseTracing ensures that all pending spans have been flushed. It should be called before process exit.

func DetailedError

func DetailedError(err error) string

DetailedError extracts a detailed error message, including stack trace, if there is one.

func Diag

func Diag() diag.Sink

Diag lazily allocates a sink to be used if we can't create a compiler.

func EmojiOr

func EmojiOr(e, or string) string

EmojiOr returns the emoji string e if emojis are enabled, or the string or if emojis are disabled.

func EndKeypadTransmitMode

func EndKeypadTransmitMode()

EndKeypadTransmitMode switches the terminal out of the keypad transmit 'application' mode back to 'normal' mode.

func ExactArgs

func ExactArgs(n int) cobra.PositionalArgs

ExactArgs is the same as cobra.ExactArgs, except it is wrapped with ArgsFunc to provide standard Pulumi error handling.

func Exit

func Exit(err error)

Exit exits with a given error.

func ExitError

func ExitError(msg string)

ExitError issues an error and exits with a standard error exit code.

func FprintTable added in v3.54.0

func FprintTable(w io.Writer, table Table) error

FprintTable prints a grid of rows and columns. Width of columns is automatically determined by the max length of the items in each column. A default gap of two spaces is printed between each column.

func GetGlobalColorization

func GetGlobalColorization() colors.Colorization

GetGlobalColorization gets the global setting for how things should be colored. This is helpful for the parts of our stack that do not take a DisplayOptions struct.

func InitDiag

func InitDiag(opts diag.FormatOptions)

InitDiag forces initialization of the diagnostics sink with the given options.

func InitProfiling

func InitProfiling(prefix string, memProfileRate int) error

func InitTracing

func InitTracing(name, rootSpanName, tracingEndpoint string)

InitTracing initializes tracing

func Interactive

func Interactive() bool

Interactive returns true if we should be running in interactive mode. That is, we have an interactive terminal session, interactivity hasn't been explicitly disabled, and we're not running in a known CI system.

func InteractiveTerminal

func InteractiveTerminal() bool

InteractiveTerminal returns true if the current terminal session is interactive.

func IsTracingEnabled

func IsTracingEnabled() bool

func IsTruthy

func IsTruthy(s string) bool

IsTruthy returns true if the given string represents a CLI input interpreted as "true".

func KillChildren

func KillChildren(pid int) error

KillChildren calls os.Process.Kill() on every child process of `pid`'s, stoping after the first error (if any). It also only kills direct child process, not any children they may have.

func MaximumNArgs

func MaximumNArgs(n int) cobra.PositionalArgs

MaximumNArgs is the same as cobra.MaximumNArgs, except it is wrapped with ArgsFunc to provide standard Pulumi error handling.

func MeasureText added in v3.17.1

func MeasureText(text string) int

MeasureText returns the number of glyphs in a string. Importantly this also ignores ANSI escape sequences, so can be used to calculate layout of colorized strings.

func MinimumNArgs

func MinimumNArgs(n int) cobra.PositionalArgs

MinimumNArgs is the same as cobra.MinimumNArgs, except it is wrapped with ArgsFunc to provide standard Pulumi error handling.

func PrintTable

func PrintTable(table Table)

PrintTable prints the table to stdout. See FprintTable for details.

func PrintTableWithGap

func PrintTableWithGap(table Table, columnGap string)

PrintTableWithGap prints a grid of rows and columns. Width of columns is automatically determined by the max length of the items in each column. A gap can be specified between the columns.

func RangeArgs

func RangeArgs(min int, max int) cobra.PositionalArgs

RangeArgs is the same as cobra.RangeArgs, except it is wrapped with ArgsFunc to provide standard Pulumi error handling.

func ReadConsole

func ReadConsole(prompt string) (string, error)

ReadConsole reads the console with the given prompt text.

func ReadConsoleNoEcho

func ReadConsoleNoEcho(prompt string) (string, error)

ReadConsoleNoEcho reads from the console without echoing. This is useful for reading passwords.

func RegisterProcessGroup

func RegisterProcessGroup(cmd *exec.Cmd)

RegisterProcessGroup informs the OS that it needs to call `setpgid` on this child process. When it comes time to kill this process, we'll kill all processes in the same process group.

func RemoveTrailingNewline

func RemoveTrailingNewline(s string) string

RemoveTrailingNewline removes a trailing newline from a string. On windows, we'll remove either \r\n or \n, on other platforms, we just remove \n.

func RunFunc

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

RunFunc wraps an error-returning run func with standard Pulumi error handling. All Pulumi commands should wrap themselves in this or RunResultFunc to ensure consistent and appropriate error behavior. In particular, we want to avoid any calls to os.Exit in the middle of a callstack which might prohibit reaping of child processes, resources, etc. And we wish to avoid the default Cobra unhandled error behavior, because it is formatted incorrectly and needlessly prints usage.

If run returns a BailError, we will not print an error message, but will still be a non-zero exit code.

func RunResultFunc

func RunResultFunc(run func(cmd *cobra.Command, args []string) result.Result) func(*cobra.Command, []string)

RunResultFunc wraps an Result-returning run func with standard Pulumi error handling. All Pulumi commands should wrap themselves in this or RunFunc to ensure consistent and appropriate error behavior. In particular, we want to avoid any calls to os.Exit in the middle of a callstack which might prohibit reaping of child processes, resources, etc. And we wish to avoid the default Cobra unhandled error behavior, because it is formatted incorrectly and needlessly prints usage.

func SetGlobalColorization

func SetGlobalColorization(value string) error

SetGlobalColorization sets the global setting for how things should be colored. This is helpful for the parts of our stack that do not take a DisplayOptions struct.

func SpecificArgs

func SpecificArgs(argNames []string) cobra.PositionalArgs

SpecificArgs requires a set of specific arguments. We use the names to improve diagnostics.

func TerminateProcessGroup added in v3.80.0

func TerminateProcessGroup(proc *os.Process, cooldown time.Duration) (ok bool, err error)

TerminateProcessGroup terminates the process group of the given process by sending a termination signal to it.

  • On Linux and macOS, it sends a SIGINT
  • On Windows, it sends a CTRL_BREAK_EVENT

If the root process does not exit gracefully within the given duration, all processes in the group are forcibly terminated.

Returns true if the process exited gracefully, false otherwise.

Returns an error if the process could not be terminated, or if the process exited with a non-zero exit code.

Types

type Spinner

type Spinner interface {
	// Tick prints the next frame of the spinner. After Tick() has been called, there should be no writes to Stdout before
	// calling Reset().
	Tick()

	// Reset is called to release ownership of stdout, so others may write to it.
	Reset()
}

Spinner represents a very simple progress reporter.

func NewSpinnerAndTicker

func NewSpinnerAndTicker(prefix string, ttyFrames []string,
	color colors.Colorization, timesPerSecond time.Duration,
	suppressProgress bool,
) (Spinner, *time.Ticker)

NewSpinnerAndTicker returns a new Spinner and a ticker that will fire an event when the next call to Spinner.Tick() should be called. NewSpinnerAndTicket takes into account if stdout is connected to a tty or not and returns either a nice animated spinner that updates quickly, using the specified ttyFrames, or a simple spinner that just prints a dot on each tick and updates slowly.

type Table

type Table struct {
	Headers []string
	Rows    []TableRow // Rows of the table.
	Prefix  string     // Optional prefix to print before each row
}

func (Table) Render added in v3.94.0

func (table Table) Render(opts *TableRenderOptions) string

func (Table) String added in v3.12.0

func (table Table) String() string

func (Table) ToStringWithGap added in v3.12.0

func (table Table) ToStringWithGap(columnGap string) string

type TableRenderOptions added in v3.94.0

type TableRenderOptions struct {
	ColumnGap   string
	HeaderStyle []colors.Color
	ColumnStyle []colors.Color
	Color       colors.Colorization
}

type TableRow

type TableRow struct {
	Columns        []string // Columns of the row
	AdditionalInfo string   // an optional line of information to print after the row
}

TableRow is a row in a table we want to print. It can be a series of a columns, followed by an additional line of information.

Jump to

Keyboard shortcuts

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