cmd

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package cmd contains helper abstractions for working with the CLI parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Content added in v0.32.0

func Content(flagval string) string

Content determines if the given flag value is a file path, and if so read the contents from disk, otherwise presume the given value is the content.

func GetActiveVersion added in v0.32.0

func GetActiveVersion(vs []*fastly.Version) (*fastly.Version, error)

GetActiveVersion returns the active service version.

func GetSpecifiedVersion added in v0.32.0

func GetSpecifiedVersion(vs []*fastly.Version, version string) (*fastly.Version, error)

GetSpecifiedVersion returns the specified service version.

func IntToBool added in v0.32.0

func IntToBool(i int) bool

IntToBool converts a binary 0|1 to a boolean.

func ServiceDetails

func ServiceDetails(opts ServiceDetailsOpts) (serviceID string, serviceVersion *fastly.Version, err error)

ServiceDetails returns the Service ID and Service Version.

Types

type AutoCloneFlagOpts

type AutoCloneFlagOpts struct {
	Action kingpin.Action
	Dst    *bool
}

AutoCloneFlagOpts enables easy configuration of the --autoclone flag defined via the RegisterAutoCloneFlag constructor.

type Base

type Base struct {
	CmdClause *kingpin.CmdClause
	Globals   *config.Data
}

Base is stuff that should be included in every concrete command.

func (Base) Name

func (b Base) Name() string

Name implements the Command interface, and returns the FullCommand from the kingpin.Command that's used to select which command to actually run.

func (Base) RegisterAutoCloneFlag added in v0.32.0

func (b Base) RegisterAutoCloneFlag(opts AutoCloneFlagOpts)

RegisterAutoCloneFlag defines a --autoclone flag that will cause a clone of the identified service version if it's found to be active or locked.

func (Base) RegisterServiceIDFlag added in v0.32.0

func (b Base) RegisterServiceIDFlag(dst *string)

RegisterServiceIDFlag defines a --service-id flag that will attempt to acquire the Service ID from multiple sources.

See: manifest.Data.ServiceID() for the sources.

func (Base) RegisterServiceVersionFlag added in v0.32.0

func (b Base) RegisterServiceVersionFlag(opts ServiceVersionFlagOpts)

RegisterServiceVersionFlag defines a --version flag that accepts multiple values such as 'latest', 'active' and numerical values which are then converted into the appropriate service version.

type Command

type Command interface {
	Name() string
	Exec(in io.Reader, out io.Writer) error
}

Command is an interface that abstracts over all of the concrete command structs. The Name method lets us select which command should be run, and the Exec method invokes whatever business logic the command should do.

func Select

func Select(name string, commands []Command) (Command, bool)

Select chooses the command matching name, if it exists.

type Globals

type Globals struct {
	Token   string
	Verbose bool
	Client  api.Interface
}

Globals are flags and other stuff that's useful to every command. Globals are passed to each concrete command's constructor as a pointer, and are populated after a call to Parse. A concrete command's Exec method can use any of the information in the globals.

type Optional

type Optional struct {
	WasSet bool
}

Optional models an optional type that consumers can use to assert whether the inner value has been set and is therefore valid for use.

func (*Optional) Set

Set implements kingpin.Action and is used as callback to set that the optional inner value is valid.

type OptionalAutoClone

type OptionalAutoClone struct {
	OptionalBool
}

OptionalAutoClone defines a method set for abstracting the logic required to identify if a given service version needs to be cloned.

func (*OptionalAutoClone) Parse

func (ac *OptionalAutoClone) Parse(v *fastly.Version, sid string, verbose bool, out io.Writer, client api.Interface) (*fastly.Version, error)

Parse returns a service version.

The returned version is either the same as the input argument `v` or it's a cloned version if the input argument was either active or locked.

type OptionalBool

type OptionalBool struct {
	Optional
	Value bool
}

OptionalBool models an optional boolean flag value.

type OptionalInt

type OptionalInt struct {
	Optional
	Value int
}

OptionalInt models an optional int flag value.

type OptionalServiceVersion

type OptionalServiceVersion struct {
	OptionalString
}

OptionalServiceVersion represents a Fastly service version.

func (*OptionalServiceVersion) Parse

func (sv *OptionalServiceVersion) Parse(sid string, client api.Interface) (*fastly.Version, error)

Parse returns a service version based on the given user input.

type OptionalString

type OptionalString struct {
	Optional
	Value string
}

OptionalString models an optional string flag value.

type OptionalStringSlice

type OptionalStringSlice struct {
	Optional
	Value []string
}

OptionalStringSlice models an optional string slice flag value.

type OptionalUint

type OptionalUint struct {
	Optional
	Value uint
}

OptionalUint models an optional uint flag value.

type OptionalUint8

type OptionalUint8 struct {
	Optional
	Value uint8
}

OptionalUint8 models an optional unit8 flag value.

type Registerer

type Registerer interface {
	Command(name, help string) *kingpin.CmdClause
}

Registerer abstracts over a kingpin.App and kingpin.CmdClause. We pass it to each concrete command struct's constructor as the "parent" into which the command should install itself.

type ServiceDetailsOpts

type ServiceDetailsOpts struct {
	AllowActiveLocked  bool
	AutoCloneFlag      OptionalAutoClone
	Client             api.Interface
	Manifest           manifest.Data
	Out                io.Writer
	ServiceVersionFlag OptionalServiceVersion
	VerboseMode        bool
}

ServiceDetailsOpts provides data and behaviours required by the ServiceDetails function.

type ServiceVersionFlagOpts

type ServiceVersionFlagOpts struct {
	Dst      *string
	Optional bool
	Action   kingpin.Action
}

ServiceVersionFlagOpts enables easy configuration of the --version flag defined via the RegisterServiceVersionFlag constructor.

NOTE: The reason we define an 'optional' field rather than a 'required' field is because 99% of the use cases where --version is defined the flag will be required, and so we cater for the common case. Meaning only those subcommands that have --version as optional will need to set that field.

Jump to

Keyboard shortcuts

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