Documentation
¶
Index ¶
- Variables
- func ArgsFunc(argsValidator cobra.PositionalArgs) cobra.PositionalArgs
- func CloseProfiling(prefix string) error
- func CloseTracing()
- func DetailedError(err error) string
- func Diag() diag.Sink
- func EmojiOr(e, or string) string
- func EndKeypadTransmitMode()
- func ExactArgs(n int) cobra.PositionalArgs
- func Exit(err error)
- func ExitError(msg string)
- func FprintTable(w io.Writer, table Table) error
- func GetGlobalColorization() colors.Colorization
- func InitDiag(opts diag.FormatOptions)
- func InitProfiling(prefix string, memProfileRate int) error
- func InitTracing(name, rootSpanName, tracingEndpoint string)
- func Interactive() bool
- func InteractiveTerminal() bool
- func IsTracingEnabled() bool
- func IsTruthy(s string) bool
- func KillChildren(pid int) error
- func MaximumNArgs(n int) cobra.PositionalArgs
- func MeasureText(text string) int
- func MinimumNArgs(n int) cobra.PositionalArgs
- func PrintTable(table Table)
- func PrintTableWithGap(table Table, columnGap string)
- func RangeArgs(minimum int, maximum int) cobra.PositionalArgs
- func ReadConsole(prompt string) (string, error)
- func ReadConsoleNoEcho(prompt string) (string, error)
- func ReadConsoleWithDefault(prompt string, defaultValue string) (string, error)
- func RegisterProcessGroup(cmd *exec.Cmd)
- func RemoveTrailingNewline(s string) string
- func RunFunc(run func(cmd *cobra.Command, args []string) error) func(*cobra.Command, []string)
- func SetGlobalColorization(value string) error
- func SpecificArgs(argNames []string) cobra.PositionalArgs
- func TerminateProcessGroup(proc *os.Process, cooldown time.Duration) (ok bool, err error)
- type Spinner
- type Table
- type TableRenderOptions
- type TableRow
Constants ¶
This section is empty.
Variables ¶
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{ "⠋", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋", } )
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 Codeinfra CLI/SDK in a programmatic way.
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.
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.
var NoArgs = ArgsFunc(cobra.NoArgs)
NoArgs is the same as cobra.NoArgs, except it is wrapped with ArgsFunc to provide standard Codeinfra error handling.
var TracingEndpoint string
TracingEndpoint is the Zipkin-compatible tracing endpoint where tracing data will be sent.
var TracingRootSpan opentracing.Span
var TracingToFile bool
TracingToFile indicates if codeinfra 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 Codeinfra error handling.
func CloseProfiling ¶
func CloseTracing ¶
func CloseTracing()
CloseTracing ensures that all pending spans have been flushed. It should be called before process exit.
func DetailedError ¶
DetailedError extracts a detailed error message, including stack trace, if there is one.
func EmojiOr ¶
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 Codeinfra error handling.
func ExitError ¶
func ExitError(msg string)
ExitError issues an error and exits with a standard error exit code.
func FprintTable ¶
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 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 ¶
IsTruthy returns true if the given string represents a CLI input interpreted as "true".
func KillChildren ¶
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 Codeinfra error handling.
func MeasureText ¶
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 Codeinfra error handling.
func PrintTable ¶
func PrintTable(table Table)
PrintTable prints the table to stdout. See FprintTable for details.
func PrintTableWithGap ¶
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(minimum int, maximum int) cobra.PositionalArgs
RangeArgs is the same as cobra.RangeArgs, except it is wrapped with ArgsFunc to provide standard Codeinfra error handling.
func ReadConsole ¶
ReadConsole reads the console with the given prompt text.
func ReadConsoleNoEcho ¶
ReadConsoleNoEcho reads from the console without echoing. This is useful for reading passwords.
func ReadConsoleWithDefault ¶
ReadConsoleWithDefault reads the console with the given prompt text with support for a default value.
func RegisterProcessGroup ¶
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 ¶
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 ¶
RunFunc wraps an error-returning run func with standard Codeinfra error handling. All Codeinfra 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 SetGlobalColorization ¶
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 ¶
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 ¶
func (table Table) Render(opts *TableRenderOptions) string