Documentation
¶
Overview ¶
Package cmdutil provides utilities that are shared between multiple commands like flags, documentation helpers and errors.
Index ¶
- Constants
- Variables
- func AddConfigFlag(cmd *cobra.Command, val *string)
- func AddForceFlag(cmd *cobra.Command, val *bool)
- func AddOverwriteFlag(cmd *cobra.Command, val *bool)
- func Examples(s string) string
- func LongDesc(s string) string
- func RenderJSON(w io.Writer, v interface{}) error
- func RenderYAML(w io.Writer, v interface{}) error
- type ConfigFlags
- type OutputFlag
- type RepositoryNotConfiguredError
- type TimeoutFlag
Constants ¶
const ( // DefaultTimeout is the default timeout for operations that cross API // boundaries. DefaultTimeout = 20 * time.Second )
Variables ¶
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 ¶
AddConfigFlag adds the --config flag to cmd and binds it to val.
func AddForceFlag ¶
AddForceFlag adds the --force flag to cmd and binds it to val.
func AddOverwriteFlag ¶
AddOverwriteFlag adds the --overwrite flag to cmd and binds it to val.
func Examples ¶
Examples formats examples for a *cobra.Command. Each line is indented by 2 spaces so that it aligns nicely with usage and flags.
func RenderJSON ¶
RenderJSON converts v to JSON and writes it to w.
func RenderYAML ¶
RenderYAML converts v to YAML and writes it to w.
Types ¶
type ConfigFlags ¶
type ConfigFlags struct {
kickoff.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 RepositoryNotConfiguredError ¶ added in v0.1.1
type RepositoryNotConfiguredError struct {
Name string
}
func (RepositoryNotConfiguredError) Error ¶ added in v0.1.1
func (e RepositoryNotConfiguredError) Error() string
Error implements the error interface.
type TimeoutFlag ¶
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.