cliopatra

package
v0.4.33 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parameter

type Parameter struct {
	Name    string                   `yaml:"name"`
	Flag    string                   `yaml:"flag,omitempty"`
	Short   string                   `yaml:"short"`
	Type    parameters.ParameterType `yaml:"type"`
	Value   interface{}              `yaml:"value"`
	Raw     string                   `yaml:"raw,omitempty"`
	NoValue bool                     `yaml:"noValue,omitempty"`
}

Parameter describes a cliopatra parameter, which can be either a flag or an argument. It does mirror the definition of parameters.ParameterDefinition, but here we only have a Value, and a Short description (which should actually describe which value we chose).

The Flag makes it possible to override the flag used on the CLI, if necessary. The Raw field makes it possible to pass a raw string to override the value being rendered out. This is useful to for example test invalid value for flags.

func (*Parameter) Clone

func (p *Parameter) Clone() *Parameter

type Program

type Program struct {
	Name        string   `yaml:"name"`
	Path        string   `yaml:"path,omitempty"`
	Verbs       []string `yaml:"verbs,omitempty"`
	Description string   `yaml:"description"`
	// Env makes it possible to specify environment variables to set manually
	Env map[string]string `yaml:"env,omitempty"`

	// TODO(manuel, 2023-03-16) Probably add RawFlags here, when we say quickly want to record a run.
	// Of course, if we are using Command, we could have that render a more precisely described
	// cliopatra file. But just capturing normal calls is nice too.
	RawFlags []string `yaml:"rawFlags,omitempty"`

	// These Flags will be passed to the CLI tool. This allows us to register
	// flags with a type to cobra itself, when exposing this command again.
	Flags []*Parameter `yaml:"flags,omitempty"`
	// Args is an ordered list of Parameters. The Flag field is ignored.
	Args []*Parameter `yaml:"args,omitempty"`
	// Stdin makes it possible to pass data into stdin. If empty, no data is passed.
	Stdin string `yaml:"stdin,omitempty"`

	// These fields are useful for golden testing.
	ExpectedStdout     string            `yaml:"expectedStdout,omitempty"`
	ExpectedError      string            `yaml:"expectedError,omitempty"`
	ExpectedStatusCode int               `yaml:"expectedStatusCode,omitempty"`
	ExpectedFiles      map[string]string `yaml:"expectedFiles,omitempty"`
}

Program describes a program to be executed by cliopatra.

This can be used for golden tests by providing and ExpectedStdout, ExpectedError, ExpectedStatusCode and ExpectedFiles.

func NewProgram

func NewProgram(opts ...ProgramOption) *Program

func NewProgramFromCapture

func NewProgramFromCapture(
	description *cmds.CommandDescription,
	ps map[string]interface{},
	opts ...ProgramOption,
) *Program

NewProgramFromCapture is a helper function to help capture a cliopatra Program from the description and the parameters map of a glazed command.

It will go over all the ParameterDefinition (from the layers, flags and arguments) and will try to create the best cliopatra map it can. It tries to resolve the prefixes of layered parameters.

Values in the parameter map that are not present under the form of a ParameterDefinition will not be added to the command, and should be added separately using the WithRawFlags option.

func NewProgramFromYAML

func NewProgramFromYAML(s io.Reader, opts ...ProgramOption) (*Program, error)

func (*Program) AddRawFlag

func (p *Program) AddRawFlag(raw ...string)

func (*Program) Clone

func (p *Program) Clone() *Program

func (*Program) ComputeArgs

func (p *Program) ComputeArgs(ps map[string]interface{}) ([]string, error)

func (*Program) RunIntoWriter

func (p *Program) RunIntoWriter(
	ctx context.Context,
	parsedLayers map[string]*layers.ParsedParameterLayer,
	ps map[string]interface{},
	w io.Writer) error

func (*Program) SetArgRaw

func (p *Program) SetArgRaw(name string, raw string) error

func (*Program) SetArgValue

func (p *Program) SetArgValue(name string, value interface{}) error

func (*Program) SetFlagRaw

func (p *Program) SetFlagRaw(name string, raw string) error

func (*Program) SetFlagValue

func (p *Program) SetFlagValue(name string, value interface{}) error

type ProgramOption

type ProgramOption func(*Program)

func WithAddArgs

func WithAddArgs(args ...*Parameter) ProgramOption

func WithAddEnv

func WithAddEnv(key, value string) ProgramOption

func WithAddFlags

func WithAddFlags(flags ...*Parameter) ProgramOption

func WithAddRawFlags

func WithAddRawFlags(flags ...string) ProgramOption

func WithArgs

func WithArgs(args ...*Parameter) ProgramOption

func WithDescription

func WithDescription(description string) ProgramOption

func WithEnv

func WithEnv(env map[string]string) ProgramOption

func WithExpectedError

func WithExpectedError(err string) ProgramOption

func WithExpectedFiles

func WithExpectedFiles(files map[string]string) ProgramOption

func WithExpectedStatusCode

func WithExpectedStatusCode(statusCode int) ProgramOption

func WithExpectedStdout

func WithExpectedStdout(stdout string) ProgramOption

func WithFlags

func WithFlags(flags ...*Parameter) ProgramOption

func WithName

func WithName(name string) ProgramOption

func WithPath

func WithPath(path string) ProgramOption

func WithRawFlags

func WithRawFlags(flags ...string) ProgramOption

func WithReplaceArgs

func WithReplaceArgs(args ...*Parameter) ProgramOption

func WithReplaceFlags

func WithReplaceFlags(flags ...*Parameter) ProgramOption

func WithStdin

func WithStdin(stdin string) ProgramOption

func WithVerbs

func WithVerbs(verbs ...string) ProgramOption

Jump to

Keyboard shortcuts

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