cmdlib

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package cmdlib contains shared functions for the bundle CLI commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 CmdIO added in v0.11.0

type CmdIO struct {
	// StdIO preforms I/O to stdout.
	StdIO StdioReaderWriter

	// FileIO performs I/O to files
	FileIO files.FileReaderWriter

	// ExitIO exits the program with some message.
	ExitIO Exiter
}

CmdIO contains dependencies for doing I/O in commands.

type Exiter added in v0.11.0

type Exiter interface {
	// Exit the program with args.
	Exit(args ...interface{})

	// Exit the program with a formatted message.
	Exitf(format string, v ...interface{})
}

Exiter is a thing that can exit with messages.

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
}

GlobalOptions are options that apply to all commands

type RealExiter added in v0.11.0

type RealExiter struct{}

RealExiter exits the program with some message.

func (*RealExiter) Exit added in v0.11.0

func (e *RealExiter) Exit(args ...interface{})

Exit calls log.Exit.

func (*RealExiter) Exitf added in v0.11.0

func (e *RealExiter) Exitf(format string, v ...interface{})

Exitf calls log.Exitf.

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