cmdutil

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSilent is an error that triggers a non zero exit code without any
	// error message.
	ErrSilent = errors.New("silent error")
	// ErrNoPromptArgRequired is raised when the application is not running
	// interactively and thus requires an argument on the command-line instead
	// of prompting for input.
	ErrNoPromptArgRequired = errors.New("argument required when not running interactively")
)

Functions

func DefaultCompletion

func DefaultCompletion(cmd *cobra.Command)

DefaultCompletion sets default values for Args and ValidArgsFunction on all child commands. If Args is nil it is set to cobra.NoArgs, if ValidArgsFunction is nil and no ValidArgs are given, it is set to NoCompletion.

func FormatCompletion added in v0.5.0

func FormatCompletion(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective)

FormatCompletion returns a completion function which completes the valid output formats of the `iofmt` package.

func InheritRootPersistenPreRun

func InheritRootPersistenPreRun(cmd *cobra.Command)

InheritRootPersistenPreRun inherits the root commands PersistenPreRunE function down to child commands which specify their own one by chaining them.

func NoCompletion

func NoCompletion(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective)

NoCompletion disables completion.

func PopulateFromArgs

func PopulateFromArgs(f *Factory, ss ...*string) cobra.PositionalArgs

PopulateFromArgs populates the given values with the argumetns given on the command-line. It returns an error if the application is not running interactively and has not enough arguments to populate all the given values. It applies cobra.MaximumNArgs() with n being the amount of values to populate.

Types

type CompletionFunc

type CompletionFunc func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

A CompletionFunc is dynamically invoked without running any of the Run() methods on the cobra.Command. Keep this in mind when implementing it, since not all factories are initialized.

func DatasetCompletionFunc

func DatasetCompletionFunc(f *Factory) CompletionFunc

DatasetCompletionFunc returns a completion function which completes the datasets from the configured deployment.

func OrganizationCompletionFunc added in v0.2.0

func OrganizationCompletionFunc(f *Factory) CompletionFunc

OrganizationCompletionFunc returns a completion function which completes the organization IDs for the active deployment.

type Factory

type Factory struct {
	// Config is the configuration.
	Config *config.Config
	// IO is the IO to be used instead of StdIn, StdOut and StdErr.
	IO *terminal.IO
}

Factory bundles resources used by most commands.

func NewFactory

func NewFactory() *Factory

NewFactory creates a new Factory.

func (*Factory) Client

func (f *Factory) Client(ctx context.Context) (*axiom.Client, error)

Client returns an Axiom client configured to talk to the active deployment.

type FlagError

type FlagError struct {
	// contains filtered or unexported fields
}

A FlagError is raised when flag processing fails.

func NewFlagError

func NewFlagError(err error) *FlagError

NewFlagError returns a new *FlagError wrapping the given error.

func NewFlagErrorf

func NewFlagErrorf(format string, a ...any) *FlagError

NewFlagErrorf returns a new, formatted *FlagError from the given format and arguments.

func (FlagError) Error

func (e FlagError) Error() string

Error implements the error interface.

func (FlagError) Unwrap

func (e FlagError) Unwrap() error

Unwrap implements unwrapping functionality.

type RunFunc

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

RunFunc is a cobra run function which is compatible with PersistentPreRunE, PreRunE, RunE, PostRunE and PersistentPostRunE.

func AsksForSetup added in v0.7.0

func AsksForSetup(f *Factory, loginCmd *cobra.Command) RunFunc

AsksForSetup will ask the user to setup Axiom in case it is not yet configured.

func ChainRunFuncs

func ChainRunFuncs(fns ...RunFunc) RunFunc

ChainRunFuncs chains one or more RunFunc's.

func NeedsActiveDeployment

func NeedsActiveDeployment(f *Factory) RunFunc

NeedsActiveDeployment makes sure an active deployment is configured. If not, it asks for one when the application is running interactively. If no deployments are configured or the application is not running interactively, an error is printed and a silent error returned.

func NeedsDatasets

func NeedsDatasets(f *Factory) RunFunc

NeedsDatasets prints an error message and errors silently if no datasets are available on the configured deployment.

func NeedsDeployments

func NeedsDeployments(f *Factory) RunFunc

NeedsDeployments prints an error message and errors silently if no deployments are configured.

func NeedsPersonalAccessToken added in v0.1.6

func NeedsPersonalAccessToken(f *Factory) RunFunc

NeedsPersonalAccessToken prints an error message and errors silently if the active deployment is not configured with a personal access token.

func NeedsRootPersistentPreRunE

func NeedsRootPersistentPreRunE() RunFunc

NeedsRootPersistentPreRunE executes the root commands PersistentPreRunE function.

func NeedsValidDeployment

func NeedsValidDeployment(f *Factory, alias *string) RunFunc

NeedsValidDeployment prints an error message and errors silently if the given deployment is not configured. An empty alias is not evaluated.

Jump to

Keyboard shortcuts

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