Documentation ¶
Overview ¶
Package root is the top of the subcommand parser
root handles setup of the command line flags and initialization of the weldr API client's configuration values. It also holds commandline flags that can be accessed by subcommands.
Index ¶
- Variables
- func AddRootCommand(cmd *cobra.Command)
- func Execute() error
- func ExecutionError(cmd *cobra.Command, format string, a ...interface{}) error
- func ExecutionErrors(cmd *cobra.Command, errors []weldr.APIErrorMsg) error
- func GetCommaArgs(args []string) []string
- func Init()
- func IsJSONList(data []byte) bool
- func LogToFile(filename, message string) error
- func MakeTarBytes(filename, data string) ([]byte, error)
- func PrintWrap(indent, columns int, s string)
- func SetupCmdTest(f func(request *http.Request) (*http.Response, error)) *weldr.MockClient
- type OutputCapture
Constants ¶
This section is empty.
Variables ¶
var ( // JSONOutput is the state of --json cmdline flag JSONOutput bool // Version is set by the build Version = "DEVEL" // Client is the weldr.Client used to communicate with the server Client weldr.Client )
Functions ¶
func AddRootCommand ¶
AddRootCommand adds a cobra command to the list of root commands
func ExecutionError ¶
ExecutionError prints an error to stderr, sets silent flags on the cobra command, and returns an error to the caller suitable for assignment to error
func ExecutionErrors ¶
func ExecutionErrors(cmd *cobra.Command, errors []weldr.APIErrorMsg) error
ExecutionErrors prints a list of errors to stderr, then calls ExecutionError
func GetCommaArgs ¶
GetCommaArgs returns a list of the arguments, split by commas and spaces They can be grouped or separated, the return list should be the same for all variations empty fields, eg. ,, are ignored by collapsing repeated , and spaces into one.
func IsJSONList ¶
IsJSONList returns true if the data unmarshals to a json list
func LogToFile ¶
LogToFile appends a line of text to a file used for debugging problems during development
func MakeTarBytes ¶
MakeTarBytes makes a simple tar file with a filename and some data in it it returns it as a slice of bytes.
func SetupCmdTest ¶
SetupCmdTest initializes the weldr client with a Mock Client used to capture test details Pass in a function to be run when the client queries the server. See weldr.
Types ¶
type OutputCapture ¶
type OutputCapture struct { Stdout *os.File Stderr *os.File // contains filtered or unexported fields }
OutputCapture holds the details used for capturing output during testing
func ExecuteTest ¶
func ExecuteTest(args ...string) (*cobra.Command, *OutputCapture, error)
ExecuteTest runs the command passed in via args and captures the output into buf returns the command executed, captured output, and any errors The captured output is stored in temporary files which can be accessed via the OutputCapture.Stdout and Outputcapture.Stderr File pointers. The caller must call .Close() on it to remove the files and restore os.Stdout and os.Stderr when it is finished.
The args passed must be a full commandline of argument, the root command parser is executed and subcommands dispatched in the same way they are during normal operation.
func NewOutputCapture ¶
func NewOutputCapture() (*OutputCapture, error)
NewOutputCapture returns an initialized struct with stdout and stderr redirected to files The user needs to call .Rewind() before reading the output And they need to call .Close() to cleanup the temporary files and restore os.Stdout and os.Stderr
func (*OutputCapture) Close ¶
func (c *OutputCapture) Close()
Close removes the temporary files and restores the original stdout/stderr
func (*OutputCapture) Rewind ¶
func (c *OutputCapture) Rewind() error
Rewind moves the file position back to the start of the capture files so they can be read.