root

package
v2.0.0-...-f345b76 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func AddRootCommand(cmd *cobra.Command)

AddRootCommand adds a cobra command to the list of root commands

func Execute

func Execute() error

Execute runs the commands on the commandline

func ExecutionError

func ExecutionError(cmd *cobra.Command, format string, a ...interface{}) error

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

func GetCommaArgs(args []string) []string

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 Init

func Init()

Init sets up Cobra and adds the doc command to the root cmdline parser

func IsJSONList

func IsJSONList(data []byte) bool

IsJSONList returns true if the data unmarshals to a json list

func LogToFile

func LogToFile(filename, message string) error

LogToFile appends a line of text to a file used for debugging problems during development

func MakeTarBytes

func MakeTarBytes(filename, data string) ([]byte, error)

MakeTarBytes makes a simple tar file with a filename and some data in it it returns it as a slice of bytes.

func PrintWrap

func PrintWrap(indent, columns int, s string)

PrintWrap prints a string wrapped at columns and subsequent lines indented

func SetupCmdTest

func SetupCmdTest(f func(request *http.Request) (*http.Response, error)) *weldr.MockClient

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.

Jump to

Keyboard shortcuts

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