cmdlib

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package cmdlib contains shared functions for the bundle CLI commands.

Index

Constants

This section is empty.

Variables

View Source
var GlobalOptionsValues = &GlobalOptions{}

GlobalOptionsValues is a global tracker for global options (for command line executions only).

Functions

func ExitWithHelp

func ExitWithHelp(cmd *cobra.Command, err string)

ExitWithHelp exits and prints the help message.

func MergeOptions added in v0.9.0

func MergeOptions(ctx context.Context, rw files.FileReaderWriter, files []string) (options.JSONOptions, error)

MergeOptions reads multiple options files and combines them into a single map. Option values will be overwritten if a later file has the same key.

func ParseStringMap added in v0.9.1

func ParseStringMap(p string) map[string]string

ParseStringMap parses a CLI flag value into a map of string to string. It expects the raw flag value to have the form "key1=value1,key2=value2,etc".

Types

type BundleReaderWriter added in v0.8.0

type BundleReaderWriter interface {
	ReadBundleData(context.Context, *GlobalOptions) (*wrapper.BundleWrapper, error)
	WriteBundleData(context.Context, *wrapper.BundleWrapper, *GlobalOptions) error
	WriteStructuredContents(context.Context, interface{}, *GlobalOptions) error
}

BundleReaderWriter provides a mockable reading / writing interface for reading / writing bundle data.

func NewBundleReaderWriter added in v0.8.0

func NewBundleReaderWriter(rw files.FileReaderWriter, stdio StdioReaderWriter) BundleReaderWriter

NewBundleReaderWriter creates a new BundleReaderWriter.

type CobraActionFunc

type CobraActionFunc func(cmd *cobra.Command, args []string)

CobraActionFunc provides a common type for all Cobra commands.

func ContextAction

ContextAction returns a CobraActionFunc for a provided ContextActionFunc.

type ContextActionFunc

type ContextActionFunc func(ctx context.Context, fio files.FileReaderWriter, sio StdioReaderWriter, cmd *cobra.Command, args []string)

ContextActionFunc is a common type for providing a context to a Cobra function.

type GlobalOptions

type GlobalOptions struct {
	// InputFile is a path to an input file. If a file is not specified, it's
	// assumed the input is provided via STDIN.
	InputFile string

	// InputFormat is the text format for the input. By default, assumes YAML
	// but also can be JSON.
	InputFormat string

	// OutputFormat is the the format for any output. By default, assumes YAML.
	OutputFormat string

	// Inline indicates whether to inline the components in the bundle builders
	// or component builders before doing any processing.
	Inline bool
}

GlobalOptions are options that apply to all commands

func (*GlobalOptions) Copy

func (g *GlobalOptions) Copy() *GlobalOptions

Copy creates an options copy.

type RealStdioReaderWriter added in v0.8.0

type RealStdioReaderWriter struct{}

RealStdioReaderWriter provides a real STDIN / STDOUT implementation.

func (*RealStdioReaderWriter) ReadAll added in v0.8.0

func (r *RealStdioReaderWriter) ReadAll() ([]byte, error)

ReadAll reads all the input from STDIN.

func (*RealStdioReaderWriter) Write added in v0.8.0

func (r *RealStdioReaderWriter) Write(b []byte) (int, error)

Write writes content to STDOUT.

type StdioReaderWriter added in v0.8.0

type StdioReaderWriter interface {
	ReadAll() ([]byte, error)
	io.Writer
}

StdioReaderWriter can read from STDIN and write to STDOUT.

Jump to

Keyboard shortcuts

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