cmdutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package cmdutil provides utilities that are shared between multiple commands like flags, documentation helpers and errors.

Index

Constants

View Source
const (
	// DefaultTimeout is the default timeout for operations that cross API
	// boundaries.
	DefaultTimeout = 20 * time.Second
)

Variables

View Source
var (
	// ErrEmptyOutputDir is returned if the user passed an empty string as the
	// output directory.
	ErrEmptyOutputDir = errors.New("output dir must not be an empty string")

	// ErrInvalidOutputFormat is returned if the output format flag contains an
	// invalid value.
	ErrInvalidOutputFormat = errors.New("--output must be 'yaml' or 'json'")
)

Functions

func AddConfigFlag

func AddConfigFlag(cmd *cobra.Command, val *string)

AddConfigFlag adds the --config flag to cmd and binds it to val.

func AddForceFlag

func AddForceFlag(cmd *cobra.Command, val *bool)

AddForceFlag adds the --force flag to cmd and binds it to val.

func AddOverwriteFlag

func AddOverwriteFlag(cmd *cobra.Command, val *bool)

AddOverwriteFlag adds the --overwrite flag to cmd and binds it to val.

func Examples

func Examples(s string) string

Examples formats examples for a *cobra.Command. Each line is indented by 2 spaces so that it aligns nicely with usage and flags.

func LongDesc

func LongDesc(s string) string

LongDesc formats the long description for a *cobra.Command.

func RenderJSON

func RenderJSON(w io.Writer, v interface{}) error

RenderJSON converts v to JSON and writes it to w.

func RenderYAML

func RenderYAML(w io.Writer, v interface{}) error

RenderYAML converts v to YAML and writes it to w.

Types

type ConfigFlags

type ConfigFlags struct {
	config.Config

	ConfigPath string
	// contains filtered or unexported fields
}

ConfigFlags provide a flag for configuring the path to the kickoff config file. Can be used to automatically populate the kickoff config with defaults and optionally override them if the user passed a different config path via the CLI flag.

func (*ConfigFlags) AddFlags

func (f *ConfigFlags) AddFlags(cmd *cobra.Command)

AddFlags adds flags for configuring the config file location to cmd.

func (*ConfigFlags) AllowMissingConfig

func (f *ConfigFlags) AllowMissingConfig()

AllowMissingConfig allows the config file at ConfigPath to be absent. A nonexistent config file will not cause errors but is simply ignored. This is useful for initialization commands to be able to specify an alternative config file which may not exist yet.

func (*ConfigFlags) Complete

func (f *ConfigFlags) Complete() (err error)

Complete completes the embedded kickoff configuration. It will load the config file from the path provided by the user and merge it into the configuration and apply configuration defaults to unset fields. Returns an error if the config file does not exist, could not be read or contains invalid configuration. If the user did not provide any config file path, the default config file will be loaded instead, if it exists.

type OutputFlag

type OutputFlag struct {
	Output string
}

OutputFlag manage and validate a flag related to output format.

func (*OutputFlag) AddFlag

func (f *OutputFlag) AddFlag(cmd *cobra.Command)

AddFlag adds the flag for configuring output format to cmd.

func (*OutputFlag) Validate

func (f *OutputFlag) Validate() error

Validate validates the output format and returns an error if the user provided an invalid value.

type TimeoutFlag

type TimeoutFlag struct {
	Timeout time.Duration
}

TimeoutFlag configure the timeout for operations that cross API boundaries, such as http requests to third-party integrations.

func NewDefaultTimeoutFlag

func NewDefaultTimeoutFlag() TimeoutFlag

NewDefaultTimeoutFlag creates a new TimeoutFlag which uses the DefaultTimeout is not overridded.

func (*TimeoutFlag) AddFlag

func (f *TimeoutFlag) AddFlag(cmd *cobra.Command)

AddFlag adds the timeout flag to cmd.

func (*TimeoutFlag) Context

func (f *TimeoutFlag) Context() (context.Context, func())

Context returns a context with the timeout set and a cancel func to cancel the context. If the timeout less or equal to zero, a normal background context is returned.

Jump to

Keyboard shortcuts

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