cmdio

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// If HTTPClient is set, it will be used for all requests made by the
	// commands that go through morc.Send. Otherwise, the default client will be
	// used. Generally, this is useful for testing; if it starts getting used
	// for other things, we may need a way of specifying via CLI args instead.
	HTTPClient *http.Client = nil
)

Functions

func OutputLoudEditAttrsResult added in v0.3.0

func OutputLoudEditAttrsResult[K CAttrKey](io IO, modifiedVals map[K]interface{}, noChangeVals map[K]interface{}, ordering []K)

OutputEditAttrsResult prints out the results of an edit operation on a set of attributes. It will print out the attributes that were modified and the attributes that were not changed.

All output is considered 'loud' and will not be printed if the IO is in quiet mode.

Edits that resulted in a mutation will be printed to the output stream and edits that did not result in a mutation will be printed to the error stream.

func SortedAttrMapKeys added in v0.3.0

func SortedAttrMapKeys[K CAttrKey, V any](m map[K]V, order []K) []K

extracts map keys in order of some strict ordering slice

Types

type AttrKey added in v0.3.0

type AttrKey interface {
	Human() string
	Name() string
}

AttrKey is an identifier for an attribute of some resource, such as the config keys of a project or a the properties of a request template. It is used for providing standardized output and sorting using OutputLoudEditAttrsResult and SortedAttrMapKeys.

type CAttrKey added in v0.3.0

type CAttrKey interface {
	comparable
	AttrKey
}

CAttrKey is an AttrKey that also implements comparable.

type IO

type IO struct {
	In  io.Reader
	Out io.Writer
	Err io.Writer

	// Quiet is set to true if the command should not print anything to the
	// output stream for PrintLoud functions. Other Print functions will still
	// print to their repspective streams (out or err).
	Quiet bool
}

IO holds the input and output streams for a command, including a settable error, output, and input stream. If Out or Err are not set, the std streams will be used when calling Println, Printf, or their error variants.

func From

func From(cmd *cobra.Command) IO

From returns an IO struct taken by retrieving streams from the given command.

func (IO) CountOf

func (io IO) CountOf(count int, word string, suffixes ...string) string

Count returns a string that automatically pluralizes the given word based on whether it is 0 or 1.

If suffixes is not set, it is assumed that the plural is formed by taking word and adding "s". If suffixes is set, the first element is used for the plural form and the second is used for the singular form.

func (IO) OnOrOff

func (io IO) OnOrOff(on bool) string

func (IO) OxfordCommaJoin added in v0.3.0

func (io IO) OxfordCommaJoin(items []string) string

func (IO) PrintErrf

func (io IO) PrintErrf(format string, args ...interface{})

func (IO) PrintErrln

func (io IO) PrintErrln(args ...interface{})

func (IO) PrintLoudErrf added in v0.3.0

func (io IO) PrintLoudErrf(format string, args ...interface{})

func (IO) PrintLoudErrln added in v0.3.0

func (io IO) PrintLoudErrln(args ...interface{})

func (IO) PrintLoudf added in v0.3.0

func (io IO) PrintLoudf(format string, args ...interface{})

func (IO) PrintLoudln added in v0.3.0

func (io IO) PrintLoudln(args ...interface{})

func (IO) Printf

func (io IO) Printf(format string, args ...interface{})

func (IO) Println

func (io IO) Println(args ...interface{})

Jump to

Keyboard shortcuts

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