cmdutil

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

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 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.

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 OutputFlags

type OutputFlags struct {
	Output string
}

OutputFlags manage and validate flags related to output format.

func (*OutputFlags) AddFlags

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

AddFlags adds flags for configuring output format to cmd.

func (*OutputFlags) Validate

func (f *OutputFlags) Validate() error

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

Jump to

Keyboard shortcuts

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