cmd

package
v1.7.2-pre Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCommonQueryFlag added in v1.6.0

func AddCommonQueryFlag(flags *pflag.FlagSet, parameters *query.Parameters)

AddCommonQueryFlag adds the CLI param that provides general query parameters

func AddFormatFlag

func AddFormatFlag(flags *pflag.FlagSet)

AddFormatFlag adds the --output (-o) flag.

func AddFormatFlagDefault added in v1.5.0

func AddFormatFlagDefault(flags *pflag.FlagSet, defValue string)

AddFormatFlagDefault is same as AddFormatFlag but allows to set default value.

func AddQueryingFlags added in v1.5.0

func AddQueryingFlags(flags *pflag.FlagSet, parameters *query.Parameters)

AddQueryingFlags adds --field-query (-f) and --label-query (-l) flags

func BuildRootCommand

func BuildRootCommand(ctx *Context) *cobra.Command

BuildRootCommand builds a new SM root command with context

func CommonConfirmationPrompt added in v1.5.0

func CommonConfirmationPrompt(message string, ctx *Context, input io.Reader) (bool, error)

CommonConfirmationPrompt provides common logic for confirmation of an operation

func CommonPrepare

func CommonPrepare(cmd Command, ctx *Context) func(*cobra.Command, []string) error

CommonPrepare provides common pre-run logic for SM commands

func CommonPrintDeclineMessage added in v1.5.0

func CommonPrintDeclineMessage(wr io.Writer)

CommonPrintDeclineMessage provides common confirmation declined message

func Execute

func Execute(cmd *cobra.Command)

Execute executes the root command

func RunE

func RunE(cmd Command) func(*cobra.Command, []string) error

RunE provides common run logic for SM commands

func SmPrepare

func SmPrepare(cmd Command, ctx *Context) func(*cobra.Command, []string) error

SmPrepare creates a SM client for SM commands

Types

type Command

type Command interface {
	Run() error
}

Command provides common logic for SM commands

type CommandPreparator

type CommandPreparator interface {
	Prepare(PrepareFunc) *cobra.Command
}

CommandPreparator used to wrap CLI commands

type ConfirmedCommand added in v1.5.0

type ConfirmedCommand interface {
	// AskForConfirmation asks user to confirm the execution of desired operation
	AskForConfirmation() (bool, error)
	// PrintDeclineMessage prints message to the user if the confirmation is declined
	PrintDeclineMessage()
}

ConfirmedCommand should be implemented if the command should ask for user confirmation prior execution

type Context

type Context struct {
	// Output should be used when printing in commands, instead of directly writing to stdout/stderr, to enable unit testing.
	Output io.Writer

	Client smclient.Client

	Verbose bool

	Configuration configuration.Configuration

	Parameters query.Parameters
}

Context is used as a context for the commands

type FormattedCommand

type FormattedCommand interface {
	// SetOutputFormat sets the command's output format
	SetOutputFormat(output.Format)
}

FormattedCommand should be implemented if the command supports different output formatting through a --format or -f flag

type Group

type Group struct {
	PrepareFn PrepareFunc
	Commands  []CommandPreparator
}

Group contains commands which have common prepare function

type HiddenUsageCommand

type HiddenUsageCommand interface {
	// HideUsage returns true when usage should be hidden and false otherwise
	HideUsage() bool
}

HiddenUsageCommand should be implemented if the command should not print its usage

type PrepareFunc

type PrepareFunc func(cmd Command, ctx *Context) func(*cobra.Command, []string) error

PrepareFunc is function type which executes common prepare logic for commands

type ValidatedCommand

type ValidatedCommand interface {
	// Validate command usage in the implementation of this method
	Validate([]string) error
}

ValidatedCommand should be implemented if the command will have validation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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