Documentation ¶
Index ¶
- type Parameter
- type Program
- func (p *Program) AddRawFlag(raw ...string)
- func (p *Program) Clone() *Program
- func (p *Program) ComputeArgs(ps map[string]interface{}) ([]string, error)
- func (p *Program) RunIntoWriter(ctx context.Context, parsedLayers map[string]*layers.ParsedParameterLayer, ...) error
- func (p *Program) SetArgRaw(name string, raw string) error
- func (p *Program) SetArgValue(name string, value interface{}) error
- func (p *Program) SetFlagRaw(name string, raw string) error
- func (p *Program) SetFlagValue(name string, value interface{}) error
- type ProgramOption
- func WithAddArgs(args ...*Parameter) ProgramOption
- func WithAddEnv(key, value string) ProgramOption
- func WithAddFlags(flags ...*Parameter) ProgramOption
- func WithAddRawFlags(flags ...string) ProgramOption
- func WithArgs(args ...*Parameter) ProgramOption
- func WithDescription(description string) ProgramOption
- func WithEnv(env map[string]string) ProgramOption
- func WithExpectedError(err string) ProgramOption
- func WithExpectedFiles(files map[string]string) ProgramOption
- func WithExpectedStatusCode(statusCode int) ProgramOption
- func WithExpectedStdout(stdout string) ProgramOption
- func WithFlags(flags ...*Parameter) ProgramOption
- func WithName(name string) ProgramOption
- func WithPath(path string) ProgramOption
- func WithRawFlags(flags ...string) ProgramOption
- func WithReplaceArgs(args ...*Parameter) ProgramOption
- func WithReplaceFlags(flags ...*Parameter) ProgramOption
- func WithStdin(stdin string) ProgramOption
- func WithVerbs(verbs ...string) ProgramOption
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.
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 (*Program) ComputeArgs ¶
func (*Program) RunIntoWriter ¶
func (*Program) SetArgValue ¶
func (*Program) SetFlagValue ¶
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