Documentation ¶
Index ¶
- Constants
- func AddSortFlag[R any](cmd *cobra.Command, sorter *multisort.Sorter[R])
- func AlreadyExistsError() error
- func GetExactlyNArgs(n int, args []string) ([]string, error)
- func GetExactlyOneArg(args []string) (string, error)
- func LabelsToMap(labels []string) (map[string]string, error)
- func MapToLabels(m map[string]string) []string
- func Must(err error)
- func NewCmds[C any, U any, R any](c *CmdsConfig[C, U, R], additionalCmds ...*cobra.Command) *cobra.Command
- func OnlyCmds(cmds ...DefaultCmd) map[DefaultCmd]bool
- func ParseSortFlags() (multisort.Keys, error)
- func PrintColoredYAML(raw []byte) string
- func Prompt() error
- func PromptCustom(c *PromptConfig) error
- func PromptDefaultAnswers() []string
- func PromptDefaultQuestion() string
- func TruncateEnd[T Truncatable](input T, maxlength int) T
- func TruncateEndEllipsis[T Truncatable](input T, ellipsis T, maxlength int) T
- func TruncateMiddle[T Truncatable](input T, maxlength int) T
- func TruncateMiddleEllipsis[T Truncatable](input T, ellipsis T, maxlength int) T
- func TruncateStart[T Truncatable](input T, maxlength int) T
- func TruncateStartEllipsis[T Truncatable](input T, ellipsis T, maxlength int) T
- func YamlIsEqual(x []byte, y []byte) (bool, error)
- type BulkAction
- type BulkResult
- type BulkResults
- type CRUD
- type CmdsConfig
- type DefaultCmd
- type GenericCLI
- func (a *GenericCLI[C, U, R]) ApplyFromFile(from string) (BulkResults[R], error)
- func (a *GenericCLI[C, U, R]) ApplyFromFileAndPrint(from string, p printers.Printer) error
- func (a *GenericCLI[C, U, R]) Create(rq C) (R, error)
- func (a *GenericCLI[C, U, R]) CreateAndPrint(rq C, p printers.Printer) error
- func (a *GenericCLI[C, U, R]) CreateFromFile(from string) (BulkResults[R], error)
- func (a *GenericCLI[C, U, R]) CreateFromFileAndPrint(from string, p printers.Printer) error
- func (a *GenericCLI[C, U, R]) Delete(id string) (R, error)
- func (a *GenericCLI[C, U, R]) DeleteAndPrint(id string, p printers.Printer) error
- func (a *GenericCLI[C, U, R]) DeleteFromFile(from string) (BulkResults[R], error)
- func (a *GenericCLI[C, U, R]) DeleteFromFileAndPrint(from string, p printers.Printer) error
- func (a *GenericCLI[C, U, R]) Describe(id string) (R, error)
- func (a *GenericCLI[C, U, R]) DescribeAndPrint(id string, p printers.Printer) error
- func (a *GenericCLI[C, U, R]) Edit(args []string) (R, error)
- func (a *GenericCLI[C, U, R]) EditAndPrint(args []string, p printers.Printer) error
- func (a *GenericCLI[C, U, R]) Interface() MultiArgCRUD[C, U, R]
- func (a *GenericCLI[C, U, R]) List(sortKeys ...multisort.Key) ([]R, error)
- func (a *GenericCLI[C, U, R]) ListAndPrint(p printers.Printer, sortKeys ...multisort.Key) error
- func (a *GenericCLI[C, U, R]) Sorter() *multisort.Sorter[R]
- func (a *GenericCLI[C, U, R]) Update(rq U) (R, error)
- func (a *GenericCLI[C, U, R]) UpdateAndPrint(rq U, p printers.Printer) error
- func (a *GenericCLI[C, U, R]) UpdateFromFile(from string) (BulkResults[R], error)
- func (a *GenericCLI[C, U, R]) UpdateFromFileAndPrint(from string, p printers.Printer) error
- func (a *GenericCLI[C, U, R]) WithBulkPrint() *GenericCLI[C, U, R]
- func (a *GenericCLI[C, U, R]) WithBulkSecurityPrompt(in io.Reader, out io.Writer) *GenericCLI[C, U, R]
- func (a *GenericCLI[C, U, R]) WithFS(fs afero.Fs) *GenericCLI[C, U, R]
- func (a *GenericCLI[C, U, R]) WithSorter(sorter *multisort.Sorter[R]) *GenericCLI[C, U, R]
- func (a *GenericCLI[C, U, R]) WithTimestamps() *GenericCLI[C, U, R]
- type MultiArgCRUD
- type MultiArgGenericCLI
- func (a *MultiArgGenericCLI[C, U, R]) ApplyFromFile(from string) (BulkResults[R], error)
- func (a *MultiArgGenericCLI[C, U, R]) ApplyFromFileAndPrint(from string, p printers.Printer) error
- func (a *MultiArgGenericCLI[C, U, R]) Create(rq C) (R, error)
- func (a *MultiArgGenericCLI[C, U, R]) CreateAndPrint(rq C, p printers.Printer) error
- func (a *MultiArgGenericCLI[C, U, R]) CreateFromFile(from string) (BulkResults[R], error)
- func (a *MultiArgGenericCLI[C, U, R]) CreateFromFileAndPrint(from string, p printers.Printer) error
- func (a *MultiArgGenericCLI[C, U, R]) Delete(id ...string) (R, error)
- func (a *MultiArgGenericCLI[C, U, R]) DeleteAndPrint(p printers.Printer, id ...string) error
- func (a *MultiArgGenericCLI[C, U, R]) DeleteFromFile(from string) (BulkResults[R], error)
- func (a *MultiArgGenericCLI[C, U, R]) DeleteFromFileAndPrint(from string, p printers.Printer) error
- func (a *MultiArgGenericCLI[C, U, R]) Describe(id ...string) (R, error)
- func (a *MultiArgGenericCLI[C, U, R]) DescribeAndPrint(p printers.Printer, id ...string) error
- func (a *MultiArgGenericCLI[C, U, R]) Edit(n int, args []string) (R, error)
- func (a *MultiArgGenericCLI[C, U, R]) EditAndPrint(n int, args []string, p printers.Printer) error
- func (a *MultiArgGenericCLI[C, U, R]) Interface() MultiArgCRUD[C, U, R]
- func (a *MultiArgGenericCLI[C, U, R]) List(sortKeys ...multisort.Key) ([]R, error)
- func (a *MultiArgGenericCLI[C, U, R]) ListAndPrint(p printers.Printer, sortKeys ...multisort.Key) error
- func (a *MultiArgGenericCLI[C, U, R]) Sorter() *multisort.Sorter[R]
- func (a *MultiArgGenericCLI[C, U, R]) Update(rq U) (R, error)
- func (a *MultiArgGenericCLI[C, U, R]) UpdateAndPrint(rq U, p printers.Printer) error
- func (a *MultiArgGenericCLI[C, U, R]) UpdateFromFile(from string) (BulkResults[R], error)
- func (a *MultiArgGenericCLI[C, U, R]) UpdateFromFileAndPrint(from string, p printers.Printer) error
- func (a *MultiArgGenericCLI[C, U, R]) WithBulkPrint() *MultiArgGenericCLI[C, U, R]
- func (a *MultiArgGenericCLI[C, U, R]) WithBulkSecurityPrompt(in io.Reader, out io.Writer) *MultiArgGenericCLI[C, U, R]
- func (a *MultiArgGenericCLI[C, U, R]) WithFS(fs afero.Fs) *MultiArgGenericCLI[C, U, R]
- func (a *MultiArgGenericCLI[C, U, R]) WithSorter(sorter *multisort.Sorter[R]) *MultiArgGenericCLI[C, U, R]
- func (a *MultiArgGenericCLI[C, U, R]) WithTimestamps() *MultiArgGenericCLI[C, U, R]
- type MultiDocumentYAML
- type PromptConfig
- type Truncatable
Constants ¶
const TruncateEllipsis = "..."
Variables ¶
This section is empty.
Functions ¶
func AddSortFlag ¶ added in v0.12.0
func AlreadyExistsError ¶
func AlreadyExistsError() error
func GetExactlyNArgs ¶ added in v0.18.3
func GetExactlyOneArg ¶
func LabelsToMap ¶
LabelsToMap splits strings at = and returns a corresponding map, errors out when there is no =.
func MapToLabels ¶
MapToLabels returns a list of labels from a label map.
func NewCmds ¶
func NewCmds[C any, U any, R any](c *CmdsConfig[C, U, R], additionalCmds ...*cobra.Command) *cobra.Command
NewCmds can be used to generate a new cobra/viper root cmd with a set of default cmds provided by the generic cli.
func OnlyCmds ¶
func OnlyCmds(cmds ...DefaultCmd) map[DefaultCmd]bool
func ParseSortFlags ¶ added in v0.12.0
func PrintColoredYAML ¶ added in v0.12.0
func PromptCustom ¶
func PromptCustom(c *PromptConfig) error
PromptCustomAnswers the user to given compare text
func PromptDefaultAnswers ¶
func PromptDefaultAnswers() []string
func PromptDefaultQuestion ¶
func PromptDefaultQuestion() string
func TruncateEnd ¶
func TruncateEnd[T Truncatable](input T, maxlength int) T
TruncateEnd will trim a string at the end.
func TruncateEndEllipsis ¶ added in v0.17.0
func TruncateEndEllipsis[T Truncatable](input T, ellipsis T, maxlength int) T
TruncateEndEllipsis will trim a string at the end and replace it with ellipsis.
func TruncateMiddle ¶
func TruncateMiddle[T Truncatable](input T, maxlength int) T
TruncateMiddle will trim a string in the middle.
func TruncateMiddleEllipsis ¶ added in v0.17.0
func TruncateMiddleEllipsis[T Truncatable](input T, ellipsis T, maxlength int) T
TruncateMiddleEllipsis will trim a string in the middle and replace it with ellipsis.
func TruncateStart ¶
func TruncateStart[T Truncatable](input T, maxlength int) T
TruncateStart will trim a string at the start.
func TruncateStartEllipsis ¶ added in v0.17.0
func TruncateStartEllipsis[T Truncatable](input T, ellipsis T, maxlength int) T
TruncateStartEllipsis will trim a string at the start and replace it with ellipsis.
Types ¶
type BulkAction ¶ added in v0.12.0
type BulkAction string
const ( BulkCreated BulkAction = "created" BulkUpdated BulkAction = "updated" BulkDeleted BulkAction = "deleted" BulkErrorOnCreate BulkAction = "error_on_create" BulkErrorOnUpdate BulkAction = "error_on_update" BulkErrorOnDelete BulkAction = "error_on_delete" )
type BulkResult ¶ added in v0.12.0
type BulkResult[R any] struct { Result R Action BulkAction Error error Duration time.Duration }
func (*BulkResult[R]) Print ¶ added in v0.12.0
func (m *BulkResult[R]) Print(p printers.Printer)
type BulkResults ¶ added in v0.12.0
type BulkResults[R any] []BulkResult[R]
type CRUD ¶
type CRUD[C any, U any, R any] interface { // Get returns the entity with the given id. Get(id string) (R, error) // List returns a slice of entities. List() ([]R, error) // Create tries to create the entity with the given request and returns the created entity. Create(rq C) (R, error) // Update tries to update the entity with the given request and returns the updated entity. Update(rq U) (R, error) // Delete tries to delete the entity with the given id and returns the deleted entity. Delete(id string) (R, error) // Convert converts an entity's response object to best possible create and update requests and additionally returns the entities ID. // This is required for capabilities like creation/update/deletion from a file of response objects. Convert(r R) (string, C, U, error) }
CRUD must be implemented in order to get generic CLI functionality.
C is the create request for an entity. U is the update request for an entity. R is the response object of an entity.
type CmdsConfig ¶
type CmdsConfig[C any, U any, R any] struct { // GenericCLI is the generic CLI used by the cobra commands. this uses only single positional arguments. if you have multiple, use multi arg generic cli. GenericCLI *GenericCLI[C, U, R] // MultiArgGenericCLI is the generic CLI used by the cobra commands. this can use n positional arguments. MultiArgGenericCLI *MultiArgGenericCLI[C, U, R] // OnlyCmds defines which default commands to include from the generic cli. if empty, all default commands will be added. OnlyCmds map[DefaultCmd]bool // BinaryName is the name of the cli binary. BinaryName string // Singular, Plural is the name of the entity for which the default cmds are generated. Singular, Plural string // Description described the entity for which the default cmds are generated. Description string // Aliases provides additional aliases for the root cmd. Aliases []string // Args defines how many arguments are being used for the entity's id and how they are named, this defaults to ["id"] Args []string // DescribePrinter is the printer that is used for describing the entity. It's a function because printers potentially get initialized later in the game. DescribePrinter func() printers.Printer // ListPrinter is the printer that is used for listing multiple entities. It's a function because printers potentially get initialized later in the game. ListPrinter func() printers.Printer // CreateRequestFromCLI if not nil, this function uses the returned create request to create the entity. CreateRequestFromCLI func() (C, error) // UpdateRequestFromCLI if not nil, this function uses the returned update request to update the entity. UpdateRequestFromCLI func(args []string) (U, error) // Sorter allows sorting the results of list commands. Sorter *multisort.Sorter[R] // ValidArgsFn is a completion function that returns the valid command line arguments. ValidArgsFn func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) // In defines from where input is read, defaults to stdin. In io.Reader // Out defines to where output is written, defaults to stdout. Out io.Writer // MutateFns can be used to customize default commands (adding additional CLI flags or something like that) RootCmdMutateFn func(cmd *cobra.Command) ListCmdMutateFn func(cmd *cobra.Command) DescribeCmdMutateFn func(cmd *cobra.Command) CreateCmdMutateFn func(cmd *cobra.Command) UpdateCmdMutateFn func(cmd *cobra.Command) DeleteCmdMutateFn func(cmd *cobra.Command) ApplyCmdMutateFn func(cmd *cobra.Command) EditCmdMutateFn func(cmd *cobra.Command) }
CmdsConfig provides the configuration for the default commands.
type DefaultCmd ¶
type DefaultCmd string
const ( ListCmd DefaultCmd = "list" DescribeCmd DefaultCmd = "describe" CreateCmd DefaultCmd = "create" UpdateCmd DefaultCmd = "update" DeleteCmd DefaultCmd = "delete" ApplyCmd DefaultCmd = "apply" EditCmd DefaultCmd = "edit" )
type GenericCLI ¶
GenericCLI can be used to gain generic CLI functionality.
C is the create request for an entity. U is the update request for an entity. R is the response object of an entity.
func NewGenericCLI ¶
func NewGenericCLI[C any, U any, R any](crud CRUD[C, U, R]) *GenericCLI[C, U, R]
NewGenericCLI returns a new generic cli.
C is the create request for an entity. U is the update request for an entity. R is the response object of an entity.
func (*GenericCLI[C, U, R]) ApplyFromFile ¶
func (a *GenericCLI[C, U, R]) ApplyFromFile(from string) (BulkResults[R], error)
func (*GenericCLI[C, U, R]) ApplyFromFileAndPrint ¶
func (a *GenericCLI[C, U, R]) ApplyFromFileAndPrint(from string, p printers.Printer) error
func (*GenericCLI[C, U, R]) Create ¶
func (a *GenericCLI[C, U, R]) Create(rq C) (R, error)
func (*GenericCLI[C, U, R]) CreateAndPrint ¶
func (a *GenericCLI[C, U, R]) CreateAndPrint(rq C, p printers.Printer) error
func (*GenericCLI[C, U, R]) CreateFromFile ¶
func (a *GenericCLI[C, U, R]) CreateFromFile(from string) (BulkResults[R], error)
func (*GenericCLI[C, U, R]) CreateFromFileAndPrint ¶
func (a *GenericCLI[C, U, R]) CreateFromFileAndPrint(from string, p printers.Printer) error
func (*GenericCLI[C, U, R]) Delete ¶
func (a *GenericCLI[C, U, R]) Delete(id string) (R, error)
func (*GenericCLI[C, U, R]) DeleteAndPrint ¶
func (a *GenericCLI[C, U, R]) DeleteAndPrint(id string, p printers.Printer) error
func (*GenericCLI[C, U, R]) DeleteFromFile ¶ added in v0.12.0
func (a *GenericCLI[C, U, R]) DeleteFromFile(from string) (BulkResults[R], error)
func (*GenericCLI[C, U, R]) DeleteFromFileAndPrint ¶ added in v0.12.0
func (a *GenericCLI[C, U, R]) DeleteFromFileAndPrint(from string, p printers.Printer) error
func (*GenericCLI[C, U, R]) Describe ¶
func (a *GenericCLI[C, U, R]) Describe(id string) (R, error)
func (*GenericCLI[C, U, R]) DescribeAndPrint ¶
func (a *GenericCLI[C, U, R]) DescribeAndPrint(id string, p printers.Printer) error
func (*GenericCLI[C, U, R]) Edit ¶
func (a *GenericCLI[C, U, R]) Edit(args []string) (R, error)
func (*GenericCLI[C, U, R]) EditAndPrint ¶
func (a *GenericCLI[C, U, R]) EditAndPrint(args []string, p printers.Printer) error
func (*GenericCLI[C, U, R]) Interface ¶
func (a *GenericCLI[C, U, R]) Interface() MultiArgCRUD[C, U, R]
Interface returns the interface that was used to create this generic cli.
func (*GenericCLI[C, U, R]) List ¶
func (a *GenericCLI[C, U, R]) List(sortKeys ...multisort.Key) ([]R, error)
func (*GenericCLI[C, U, R]) ListAndPrint ¶
func (*GenericCLI[C, U, R]) Sorter ¶ added in v0.11.0
func (a *GenericCLI[C, U, R]) Sorter() *multisort.Sorter[R]
Sorter returns the sorter of this generic cli.
func (*GenericCLI[C, U, R]) Update ¶
func (a *GenericCLI[C, U, R]) Update(rq U) (R, error)
func (*GenericCLI[C, U, R]) UpdateAndPrint ¶
func (a *GenericCLI[C, U, R]) UpdateAndPrint(rq U, p printers.Printer) error
func (*GenericCLI[C, U, R]) UpdateFromFile ¶
func (a *GenericCLI[C, U, R]) UpdateFromFile(from string) (BulkResults[R], error)
func (*GenericCLI[C, U, R]) UpdateFromFileAndPrint ¶
func (a *GenericCLI[C, U, R]) UpdateFromFileAndPrint(from string, p printers.Printer) error
func (*GenericCLI[C, U, R]) WithBulkPrint ¶ added in v0.12.0
func (a *GenericCLI[C, U, R]) WithBulkPrint() *GenericCLI[C, U, R]
WithBulkPrint prints results in a bulk at the end on multi-entity operations, the results are a list. default is printing results intermediately during the bulk operation, which causes single entities to be printed in sequence.
func (*GenericCLI[C, U, R]) WithBulkSecurityPrompt ¶ added in v0.12.0
func (a *GenericCLI[C, U, R]) WithBulkSecurityPrompt(in io.Reader, out io.Writer) *GenericCLI[C, U, R]
WithBulkSecurityPrompt prints interactive prompts before a multi-entity operation if there is a tty.
func (*GenericCLI[C, U, R]) WithFS ¶
func (a *GenericCLI[C, U, R]) WithFS(fs afero.Fs) *GenericCLI[C, U, R]
func (*GenericCLI[C, U, R]) WithSorter ¶ added in v0.11.0
func (a *GenericCLI[C, U, R]) WithSorter(sorter *multisort.Sorter[R]) *GenericCLI[C, U, R]
func (*GenericCLI[C, U, R]) WithTimestamps ¶ added in v0.12.0
func (a *GenericCLI[C, U, R]) WithTimestamps() *GenericCLI[C, U, R]
WithBulkTimestamps prints out the duration of an operation to stdout during a bulk operation.
type MultiArgCRUD ¶ added in v0.18.3
type MultiArgCRUD[C any, U any, R any] interface { // Get returns the entity with the given id. It can be that multiple ids are passed in case the id is a compound key. Get(id ...string) (R, error) // List returns a slice of entities. List() ([]R, error) // Create tries to create the entity with the given request and returns the created entity. Create(rq C) (R, error) // Update tries to update the entity with the given request and returns the updated entity. Update(rq U) (R, error) // Delete tries to delete the entity with the given id and returns the deleted entity. It can be that multiple ids are passed in case the id is a compound key. Delete(id ...string) (R, error) // Convert converts an entity's response object to best possible create and update requests and additionally returns the entities ID. // This is required for capabilities like creation/update/deletion from a file of response objects. Convert(r R) ([]string, C, U, error) }
MultiArgCRUD must be implemented in order to get generic CLI functionality.
C is the create request for an entity. U is the update request for an entity. R is the response object of an entity.
type MultiArgGenericCLI ¶ added in v0.18.3
MultiArgGenericCLI can be used to gain generic CLI functionality.
C is the create request for an entity. U is the update request for an entity. R is the response object of an entity.
func NewGenericMultiArgCLI ¶ added in v0.18.3
func NewGenericMultiArgCLI[C any, U any, R any](crud MultiArgCRUD[C, U, R]) *MultiArgGenericCLI[C, U, R]
NewGenericMultiArgCLI returns a new generic cli.
C is the create request for an entity. U is the update request for an entity. R is the response object of an entity.
func (*MultiArgGenericCLI[C, U, R]) ApplyFromFile ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) ApplyFromFile(from string) (BulkResults[R], error)
ApplyFromFile creates or updates entities from a given file of response entities. In order to work, the create function must return an already exists error as defined in this package.
As this function uses response entities, it is possible that create and update entity representation is inaccurate to a certain degree.
func (*MultiArgGenericCLI[C, U, R]) ApplyFromFileAndPrint ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) ApplyFromFileAndPrint(from string, p printers.Printer) error
func (*MultiArgGenericCLI[C, U, R]) Create ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) Create(rq C) (R, error)
func (*MultiArgGenericCLI[C, U, R]) CreateAndPrint ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) CreateAndPrint(rq C, p printers.Printer) error
func (*MultiArgGenericCLI[C, U, R]) CreateFromFile ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) CreateFromFile(from string) (BulkResults[R], error)
CreateFromFile creates entities from a given file containing response entities.
As this function uses response entities, it is possible that create and update entity representation is inaccurate to a certain degree.
func (*MultiArgGenericCLI[C, U, R]) CreateFromFileAndPrint ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) CreateFromFileAndPrint(from string, p printers.Printer) error
func (*MultiArgGenericCLI[C, U, R]) Delete ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) Delete(id ...string) (R, error)
func (*MultiArgGenericCLI[C, U, R]) DeleteAndPrint ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) DeleteAndPrint(p printers.Printer, id ...string) error
func (*MultiArgGenericCLI[C, U, R]) DeleteFromFile ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) DeleteFromFile(from string) (BulkResults[R], error)
DeleteFromFile updates a single entity from a given file containing a response entity.
As this function uses response entities, it is possible that create and update entity representation is inaccurate to a certain degree.
func (*MultiArgGenericCLI[C, U, R]) DeleteFromFileAndPrint ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) DeleteFromFileAndPrint(from string, p printers.Printer) error
func (*MultiArgGenericCLI[C, U, R]) Describe ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) Describe(id ...string) (R, error)
func (*MultiArgGenericCLI[C, U, R]) DescribeAndPrint ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) DescribeAndPrint(p printers.Printer, id ...string) error
func (*MultiArgGenericCLI[C, U, R]) Edit ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) Edit(n int, args []string) (R, error)
func (*MultiArgGenericCLI[C, U, R]) EditAndPrint ¶ added in v0.18.3
func (*MultiArgGenericCLI[C, U, R]) Interface ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) Interface() MultiArgCRUD[C, U, R]
Interface returns the interface that was used to create this generic cli.
func (*MultiArgGenericCLI[C, U, R]) List ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) List(sortKeys ...multisort.Key) ([]R, error)
func (*MultiArgGenericCLI[C, U, R]) ListAndPrint ¶ added in v0.18.3
func (*MultiArgGenericCLI[C, U, R]) Sorter ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) Sorter() *multisort.Sorter[R]
Sorter returns the sorter of this generic cli.
func (*MultiArgGenericCLI[C, U, R]) Update ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) Update(rq U) (R, error)
func (*MultiArgGenericCLI[C, U, R]) UpdateAndPrint ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) UpdateAndPrint(rq U, p printers.Printer) error
func (*MultiArgGenericCLI[C, U, R]) UpdateFromFile ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) UpdateFromFile(from string) (BulkResults[R], error)
UpdateFromFile updates entities from a given file containing response entities.
As this function uses response entities, it is possible that create and update entity representation is inaccurate to a certain degree.
func (*MultiArgGenericCLI[C, U, R]) UpdateFromFileAndPrint ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) UpdateFromFileAndPrint(from string, p printers.Printer) error
func (*MultiArgGenericCLI[C, U, R]) WithBulkPrint ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) WithBulkPrint() *MultiArgGenericCLI[C, U, R]
WithBulkPrint prints results in a bulk at the end on multi-entity operations, the results are a list. default is printing results intermediately during the bulk operation, which causes single entities to be printed in sequence.
func (*MultiArgGenericCLI[C, U, R]) WithBulkSecurityPrompt ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) WithBulkSecurityPrompt(in io.Reader, out io.Writer) *MultiArgGenericCLI[C, U, R]
WithBulkSecurityPrompt prints interactive prompts before a multi-entity operation if there is a tty.
func (*MultiArgGenericCLI[C, U, R]) WithFS ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) WithFS(fs afero.Fs) *MultiArgGenericCLI[C, U, R]
func (*MultiArgGenericCLI[C, U, R]) WithSorter ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) WithSorter(sorter *multisort.Sorter[R]) *MultiArgGenericCLI[C, U, R]
func (*MultiArgGenericCLI[C, U, R]) WithTimestamps ¶ added in v0.18.3
func (a *MultiArgGenericCLI[C, U, R]) WithTimestamps() *MultiArgGenericCLI[C, U, R]
WithBulkTimestamps prints out the duration of an operation to stdout during a bulk operation.
type MultiDocumentYAML ¶
type MultiDocumentYAML[D any] struct { // contains filtered or unexported fields }
MultiDocumentYAML offers functions on multidocument YAML files
func NewMultiDocumentYAML ¶
func NewMultiDocumentYAML[D any]() *MultiDocumentYAML[D]
func (*MultiDocumentYAML[D]) ReadAll ¶
func (m *MultiDocumentYAML[D]) ReadAll(from string) ([]D, error)
ReadAll reads all documents from a multi-document YAML from a given path
func (*MultiDocumentYAML[D]) ReadIndex ¶
func (m *MultiDocumentYAML[D]) ReadIndex(from string, index int) (D, error)
ReadIndex reads a document from a specific index of a multi-document YAML from a given path
func (*MultiDocumentYAML[D]) ReadOne ¶
func (m *MultiDocumentYAML[D]) ReadOne(from string) (D, error)
ReadOne reads exactly one document from a multi-document YAML from a given path, returns an error if there are no or more than one documents in it
type PromptConfig ¶
type PromptConfig struct { // Message is a message shown by the prompt before the input prompt Message string // ShowAnswers shows the accepted answers when set to true ShowAnswers bool // AcceptedAnswers contains the accepted answers to make the prompt succeed AcceptedAnswers []string // DefaultAnswer is an optional prompt configuration that uses this answer in case the input closes without any content, it needs to be contained in the list of accepted answers or needs to be the "no" answer DefaultAnswer string // No is shown in addition to the accepted answers, can be empty No string In io.Reader Out io.Writer }
type Truncatable ¶
type Truncatable interface { ~string }