utils

package
v2.0.0-...-98cc131 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckForUnknown

func CheckForUnknown(fldPath *field.Path, orig, accepted interface{}) field.ErrorList

func CheckForUnknownElements

func CheckForUnknownElements(fldPath *field.Path, orig, accepted []interface{}) field.ErrorList

func CheckForUnknownFields

func CheckForUnknownFields(fldPath *field.Path, orig, accepted map[string]interface{}) field.ErrorList

func HandleArgs

func HandleArgs(opts *output.Options, handler TypeHandler, args ...string) error

func HandleOutput

func HandleOutput(output output.Output, handler TypeHandler, specs ...ElemSpec) error

func HandleOutputs

func HandleOutputs(opts *output.Options, handler TypeHandler, args ...ElemSpec) error

func HideCommand

func HideCommand(cmd *cobra.Command) *cobra.Command

func MassageCommand

func MassageCommand(cmd *cobra.Command, names ...string) *cobra.Command

func Names

func Names(def []string, names ...string) []string

func Plural

func Plural[N constraints.Integer](s string, amount ...N) string

func SetupCommand

func SetupCommand(ocmcmd OCMCommand, names ...string) *cobra.Command

SetupCommand uses the OCMCommand to create and tweak a cobra command to incorporate the additional reusable option specs and their usage documentation. Before the command executions the various Complete method flavors are executed on the additional options ond the OCMCommand. It also prepares the help system to reflect dynamic settings provided by root command options by using a generated update function based on optional methods of the OCM command.

Types

type BaseCommand

type BaseCommand struct {
	clictx.Context
	options.OptionSet
}

BaseCommand provides the basic functionality of an OCM command to carry a context and a set of reusable option specs.

func NewBaseCommand

func NewBaseCommand(ctx clictx.Context, opts ...options.Options) BaseCommand

func (BaseCommand) Complete

func (BaseCommand) Complete(args []string) error

type CommandTweaker

type CommandTweaker interface {
	TweakCommand(cmd *cobra.Command)
}

type ElemSpec

type ElemSpec interface {
	String() string
}

func ElemSpecs

func ElemSpecs(list interface{}) ([]ElemSpec, error)

func StringElemSpecs

func StringElemSpecs(args ...string) []ElemSpec

type Example

type Example interface {
	Example() string
}

Example is used to provide the example description by a method of the command.

type Long

type Long interface {
	Long() string
}

Long is used to provide the long description by a method of the command.

type OCMCommand

type OCMCommand interface {
	clictx.Context

	// ForName create a new cobra command for the given command name.
	// The Use attribute should omit the command name and just provide
	// a ost argument synopsis.
	// the complete attribute set is tweaked with the SetupCommand function
	// which calls this method.
	// Basically this should be an inherited function by the base implementation
	// but GO does not support virtual methods, therefore it is a global
	// function instead of a method.
	ForName(name string) *cobra.Command
	AddFlags(fs *pflag.FlagSet)
	Complete(args []string) error
	Run() error
}

OCMCommand is a command pattern, that can be instantiated for a dediated sub command name to create a cobra command.

type Short

type Short interface {
	Short() string
}

Short is used to provide the short description by a method of the command.

type StringSpec

type StringSpec string

func (StringSpec) String

func (s StringSpec) String() string

type TypeHandler

type TypeHandler interface {
	// All returns all elements according to its context
	All() ([]output.Object, error)
	// Get returns the elements for a dedicated specification
	// according to the handlers context.
	Get(name ElemSpec) ([]output.Object, error)
	Close() error
}

TypeHandler provides base input to an output processing chain using HandleArsg or HandleOutput(s). It provides the exploding of intials specifications to effective objects passed to the output processing chain.

type Updater

type Updater interface {
	Update(cmd *cobra.Command, args []string)
}

Updater is a generic update function.

Jump to

Keyboard shortcuts

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