cli

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Help added in v0.9.0

func Help(cmd Command) string

Help returns extended usage information

func Usage added in v0.9.0

func Usage(cmd Command) string

Usage returns usage information

Types

type AddCommand added in v0.10.0

type AddCommand struct {
	// contains filtered or unexported fields
}

AddCommand container for all 'append' parameters

func NewAddCommand added in v0.10.0

func NewAddCommand(c *client.Client) *AddCommand

NewAddCommand creates a new AddCommand parameter container

func (*AddCommand) GetArgs added in v0.10.0

func (cmd *AddCommand) GetArgs() interface{}

GetArgs provides the struct holding arguments for the command

func (*AddCommand) GetName added in v0.10.0

func (cmd *AddCommand) GetName() string

GetName returns the AddCommand's name identifier

func (*AddCommand) IsSane added in v0.10.0

func (cmd *AddCommand) IsSane() bool

IsSane returns true if command is sane

func (*AddCommand) Parse added in v0.10.0

func (cmd *AddCommand) Parse(args []string) error

Parse parses the arguments into the Command and Args structs

func (*AddCommand) PrintUsage added in v0.10.0

func (cmd *AddCommand) PrintUsage()

PrintUsage print command usage

func (*AddCommand) Run added in v0.10.0

func (cmd *AddCommand) Run() int

Run executes 'add' with given AddCommand's parameters

type AddCommandArgs added in v0.10.0

type AddCommandArgs struct {
	Key     string `arg:"positional,required"`
	Value   string `arg:"positional,required"`
	Path    string `arg:"positional,required"`
	Force   bool   `arg:"-f,--force" help:"Overwrite key if exists"`
	Confirm bool   `arg:"-y,--confirm" help:"Write results without prompt"`
	DryRun  bool   `arg:"-n,--dry-run" help:"Skip writing results without prompt"`
}

AddCommandArgs provides a struct for go-arg parsing

func (AddCommandArgs) Description added in v0.10.0

func (AddCommandArgs) Description() string

Description provides detail on what the command does

type AppendCommand added in v0.6.0

type AppendCommand struct {
	Mode AppendMode
	// contains filtered or unexported fields
}

AppendCommand container for all 'append' parameters

func NewAppendCommand added in v0.6.0

func NewAppendCommand(c *client.Client) *AppendCommand

NewAppendCommand creates a new AppendCommand parameter container

func (*AppendCommand) GetArgs added in v0.9.0

func (cmd *AppendCommand) GetArgs() interface{}

GetArgs provides the struct holding arguments for the command

func (*AppendCommand) GetName added in v0.6.0

func (cmd *AppendCommand) GetName() string

GetName returns the AppendCommand's name identifier

func (*AppendCommand) IsSane added in v0.6.0

func (cmd *AppendCommand) IsSane() bool

IsSane returns true if command is sane

func (*AppendCommand) Parse added in v0.6.0

func (cmd *AppendCommand) Parse(args []string) error

Parse parses the arguments into the Command and Args structs

func (*AppendCommand) PrintUsage added in v0.7.1

func (cmd *AppendCommand) PrintUsage()

PrintUsage print command usage

func (*AppendCommand) Run added in v0.6.0

func (cmd *AppendCommand) Run() int

Run executes 'append' with given AppendCommand's parameters

type AppendCommandArgs added in v0.9.0

type AppendCommandArgs struct {
	Source string `arg:"positional,required"`
	Target string `arg:"positional,required"`
	Force  bool   `arg:"-f,--force" help:"Overwrite key if exists"`
	Skip   bool   `arg:"-s,--skip" help:"Skip key if exists (default)"`
	Rename bool   `arg:"-r,--rename" help:"Rename key if exists"`
}

AppendCommandArgs provides a struct for go-arg parsing

func (AppendCommandArgs) Description added in v0.9.0

func (AppendCommandArgs) Description() string

Description provides detail on what the command does

type AppendMode added in v0.6.0

type AppendMode string

AppendMode defines behaviour in case existing secrets are in conflict

const (
	// ModeSkip do not append secret on conflict
	ModeSkip AppendMode = "skip"
	// ModeOverwrite overwrite existing secret on conflict
	ModeOverwrite AppendMode = "overwrite"
	// ModeRename keep existing secret and create a new key on conflict
	ModeRename AppendMode = "rename"
	// ModeInvalid denotes invalid mode
	ModeInvalid AppendMode = "invalid"
)

type CatCommand

type CatCommand struct {
	// contains filtered or unexported fields
}

CatCommand container for all 'cat' parameters

func NewCatCommand

func NewCatCommand(c *client.Client) *CatCommand

NewCatCommand creates a new CatCommand parameter container

func (*CatCommand) GetArgs added in v0.9.0

func (cmd *CatCommand) GetArgs() interface{}

GetArgs provides the struct holding arguments for the command

func (*CatCommand) GetName

func (cmd *CatCommand) GetName() string

GetName returns the CatCommand's name identifier

func (*CatCommand) IsSane added in v0.1.1

func (cmd *CatCommand) IsSane() bool

IsSane returns true if command is sane

func (*CatCommand) Parse added in v0.1.1

func (cmd *CatCommand) Parse(args []string) error

Parse given arguments and return status

func (*CatCommand) PrintUsage added in v0.7.1

func (cmd *CatCommand) PrintUsage()

PrintUsage print command usage

func (*CatCommand) Run

func (cmd *CatCommand) Run() int

Run executes 'cat' with given CatCommand's parameters

type CatCommandArgs added in v0.9.0

type CatCommandArgs struct {
	Path string `arg:"positional,required" help:"path to display contents"`
}

CatCommandArgs provides a struct for go-arg parsing

func (CatCommandArgs) Description added in v0.9.0

func (CatCommandArgs) Description() string

Description provides detail on what the command does

type CdCommand

type CdCommand struct {
	// contains filtered or unexported fields
}

CdCommand container for all 'cd' parameters

func NewCdCommand

func NewCdCommand(c *client.Client) *CdCommand

NewCdCommand creates a new CdCommand parameter container

func (*CdCommand) GetArgs added in v0.9.0

func (cmd *CdCommand) GetArgs() interface{}

GetArgs provides the struct holding arguments for the command

func (*CdCommand) GetName

func (cmd *CdCommand) GetName() string

GetName returns the CdCommand's name identifier

func (*CdCommand) IsSane added in v0.1.1

func (cmd *CdCommand) IsSane() bool

IsSane returns true if command is sane

func (*CdCommand) Parse added in v0.1.1

func (cmd *CdCommand) Parse(args []string) error

Parse given arguments and return status

func (*CdCommand) PrintUsage added in v0.7.1

func (cmd *CdCommand) PrintUsage()

PrintUsage print command usage

func (*CdCommand) Run

func (cmd *CdCommand) Run() int

Run executes 'cd' with given CdCommand's parameters

type CdCommandArgs added in v0.9.0

type CdCommandArgs struct {
	Path string `arg:"positional,required" help:"change cwd to path"`
}

CdCommandArgs provides a struct for go-arg parsing

func (CdCommandArgs) Description added in v0.9.0

func (CdCommandArgs) Description() string

Description provides detail on what the command does

type Command

type Command interface {
	Run() int
	GetName() string
	GetArgs() interface{}
	IsSane() bool
	PrintUsage()
	Parse(args []string) error
}

Command interface to describe a command structure

type Commands added in v0.7.2

type Commands struct {
	Add     *AddCommand
	Append  *AppendCommand
	Cat     *CatCommand
	Cd      *CdCommand
	Cp      *CopyCommand
	Grep    *GrepCommand
	Ls      *ListCommand
	Mv      *MoveCommand
	Replace *ReplaceCommand
	Rm      *RemoveCommand
}

Commands contains all available commands

func NewCommands added in v0.7.2

func NewCommands(client *client.Client) *Commands

NewCommands returns a Commands struct with all available commands

func (*Commands) Get added in v0.10.0

func (cmds *Commands) Get(cmd string) Command

Get returns the Command that matches the string

type CopyCommand

type CopyCommand struct {
	// contains filtered or unexported fields
}

CopyCommand container for all 'cp' parameters

func NewCopyCommand

func NewCopyCommand(c *client.Client) *CopyCommand

NewCopyCommand creates a new CopyCommand parameter container

func (*CopyCommand) GetArgs added in v0.9.0

func (cmd *CopyCommand) GetArgs() interface{}

GetArgs provides the struct holding arguments for the command

func (*CopyCommand) GetName

func (cmd *CopyCommand) GetName() string

GetName returns the CopyCommand's name identifier

func (*CopyCommand) IsSane added in v0.1.1

func (cmd *CopyCommand) IsSane() bool

IsSane returns true if command is sane

func (*CopyCommand) Parse added in v0.1.1

func (cmd *CopyCommand) Parse(args []string) error

Parse given arguments and return status

func (*CopyCommand) PrintUsage added in v0.7.1

func (cmd *CopyCommand) PrintUsage()

PrintUsage print command usage

func (*CopyCommand) Run

func (cmd *CopyCommand) Run() int

Run executes 'cp' with given CopyCommand's parameters

type CopyCommandArgs added in v0.9.0

type CopyCommandArgs struct {
	Source string `arg:"positional,required" help:"path to copy from"`
	Target string `arg:"positional,required" help:"path to copy to"`
}

CopyCommandArgs provides a struct for go-arg parsing

func (CopyCommandArgs) Description added in v0.9.0

func (CopyCommandArgs) Description() string

Description provides detail on what the command does

type GrepCommand added in v0.5.0

type GrepCommand struct {
	Mode KeyValueMode
	// contains filtered or unexported fields
}

GrepCommand container for all 'grep' parameters

func NewGrepCommand added in v0.5.0

func NewGrepCommand(c *client.Client) *GrepCommand

NewGrepCommand creates a new GrepCommand parameter container

func (*GrepCommand) GetArgs added in v0.9.0

func (cmd *GrepCommand) GetArgs() interface{}

GetArgs provides the struct holding arguments for the command

func (*GrepCommand) GetName added in v0.5.0

func (cmd *GrepCommand) GetName() string

GetName returns the GrepCommand's name identifier

func (*GrepCommand) GetSearchParams added in v0.9.0

func (cmd *GrepCommand) GetSearchParams() SearchParameters

GetSearchParams returns the search parameters the command was run with

func (*GrepCommand) IsSane added in v0.5.0

func (cmd *GrepCommand) IsSane() bool

IsSane returns true if command is sane

func (*GrepCommand) Parse added in v0.5.0

func (cmd *GrepCommand) Parse(args []string) error

Parse given arguments and return status

func (*GrepCommand) PrintUsage added in v0.7.1

func (cmd *GrepCommand) PrintUsage()

PrintUsage print command usage

func (*GrepCommand) Run added in v0.5.0

func (cmd *GrepCommand) Run() int

Run executes 'grep' with given GrepCommand's parameters

type GrepCommandArgs added in v0.9.0

type GrepCommandArgs struct {
	Search  string `arg:"positional,required"`
	Path    string `arg:"positional"`
	Keys    bool   `arg:"-k,--keys" help:"Match against keys (true if -v is not specified)"`
	Regexp  bool   `arg:"-e,--regexp" help:"Treat search string as a regexp"`
	Shallow bool   `arg:"-S,--shallow" help:"Only search leaf nodes of the path rather than recurse deeper"`
	Values  bool   `arg:"-v,--values" help:"Match against values (true if -k is not specified)"`
}

GrepCommandArgs provides a struct for go-arg parsing

func (GrepCommandArgs) Description added in v0.9.0

func (GrepCommandArgs) Description() string

Description provides detail on what the command does

type KeyValueCommand added in v0.9.0

type KeyValueCommand interface {
	IsMode(mode KeyValueMode) bool
}

KeyValueCommand interface to describe a command that supports Key and/or Value scoping

type KeyValueMode added in v0.9.0

type KeyValueMode int

KeyValueMode defines the scope of which parts of a path to search (keys and/or values)

const (
	// ModeKeys only searches keys
	ModeKeys KeyValueMode = 1
	// ModeValues only searches values
	ModeValues KeyValueMode = 2
)

type ListCommand

type ListCommand struct {
	// contains filtered or unexported fields
}

ListCommand container for 'ls' parameters

func NewListCommand

func NewListCommand(c *client.Client) *ListCommand

NewListCommand creates a new ListCommand parameter container

func (*ListCommand) GetArgs added in v0.9.0

func (cmd *ListCommand) GetArgs() interface{}

GetArgs provides the struct holding arguments for the command

func (*ListCommand) GetName

func (cmd *ListCommand) GetName() string

GetName returns the ListCommand's name identifier

func (*ListCommand) IsSane added in v0.1.1

func (cmd *ListCommand) IsSane() bool

IsSane returns true if command is sane

func (*ListCommand) Parse added in v0.1.1

func (cmd *ListCommand) Parse(args []string) error

Parse given arguments and return status

func (*ListCommand) PrintUsage added in v0.7.1

func (cmd *ListCommand) PrintUsage()

PrintUsage print command usage

func (*ListCommand) Run

func (cmd *ListCommand) Run() int

Run executes 'ls' with given ListCommand's parameters

type ListCommandArgs added in v0.9.0

type ListCommandArgs struct {
	Path string `arg:"positional" help:"path to list contents of, defaults to current path"`
}

ListCommandArgs provides a struct for go-arg parsing

func (ListCommandArgs) Description added in v0.9.0

func (ListCommandArgs) Description() string

Description provides detail on what the command does

type Match added in v0.5.0

type Match struct {
	// contains filtered or unexported fields
}

Match structure to keep indices of matched and replaced terms

type MatchOutput added in v0.10.0

type MatchOutput string

MatchOutput contains the possible ways of presenting a match

const (
	// MatchOutputHighlight outputs yellow highlighted matching text
	MatchOutputHighlight MatchOutput = "highlight"
	// MatchOutputInline outputs red and green text to show replacements
	MatchOutputInline MatchOutput = "inline"
	// MatchOutputDiff outputs addition and subtraction lines to show replacements
	MatchOutputDiff MatchOutput = "diff"
)

type MatchOutputArg added in v0.10.0

type MatchOutputArg struct {
	Value MatchOutput
}

MatchOutputArg provides a struct to custom validate an arg

func (*MatchOutputArg) UnmarshalText added in v0.10.0

func (a *MatchOutputArg) UnmarshalText(b []byte) error

UnmarshalText validates the MatchOutputArg

type MoveCommand

type MoveCommand struct {
	// contains filtered or unexported fields
}

MoveCommand container for all 'mv' parameters

func NewMoveCommand

func NewMoveCommand(c *client.Client) *MoveCommand

NewMoveCommand creates a new MoveCommand parameter container

func (*MoveCommand) GetArgs added in v0.9.0

func (cmd *MoveCommand) GetArgs() interface{}

GetArgs provides the struct holding arguments for the command

func (*MoveCommand) GetName

func (cmd *MoveCommand) GetName() string

GetName returns the MoveCommand's name identifier

func (*MoveCommand) IsSane added in v0.1.1

func (cmd *MoveCommand) IsSane() bool

IsSane returns true if command is sane

func (*MoveCommand) Parse added in v0.1.1

func (cmd *MoveCommand) Parse(args []string) error

Parse given arguments and return status

func (*MoveCommand) PrintUsage added in v0.7.1

func (cmd *MoveCommand) PrintUsage()

PrintUsage print command usage

func (*MoveCommand) Run

func (cmd *MoveCommand) Run() int

Run executes 'mv' with given MoveCommand's parameters

type MoveCommandArgs added in v0.9.0

type MoveCommandArgs struct {
	Source string `arg:"positional,required" help:"path to move"`
	Target string `arg:"positional,required" help:"path to move source to"`
}

MoveCommandArgs provides a struct for go-arg parsing

func (MoveCommandArgs) Description added in v0.9.0

func (MoveCommandArgs) Description() string

Description provides detail on what the command does

type RemoveCommand

type RemoveCommand struct {
	// contains filtered or unexported fields
}

RemoveCommand container for all 'rm' parameters

func NewRemoveCommand

func NewRemoveCommand(c *client.Client) *RemoveCommand

NewRemoveCommand creates a new RemoveCommand parameter container

func (*RemoveCommand) GetArgs added in v0.9.0

func (cmd *RemoveCommand) GetArgs() interface{}

GetArgs provides the struct holding arguments for the command

func (*RemoveCommand) GetName

func (cmd *RemoveCommand) GetName() string

GetName returns the RemoveCommand's name identifier

func (*RemoveCommand) IsSane added in v0.1.1

func (cmd *RemoveCommand) IsSane() bool

IsSane returns true if command is sane

func (*RemoveCommand) Parse added in v0.1.1

func (cmd *RemoveCommand) Parse(args []string) error

Parse given arguments and return status

func (*RemoveCommand) PrintUsage added in v0.7.1

func (cmd *RemoveCommand) PrintUsage()

PrintUsage print command usage

func (*RemoveCommand) Run

func (cmd *RemoveCommand) Run() int

Run executes 'rm' with given RemoveCommand's parameters

type RemoveCommandArgs added in v0.9.0

type RemoveCommandArgs struct {
	Path string `arg:"positional,required" help:"path to remove"`
}

RemoveCommandArgs provides a struct for go-arg parsing

func (RemoveCommandArgs) Description added in v0.9.0

func (RemoveCommandArgs) Description() string

Description provides detail on what the command does

type ReplaceCommand added in v0.9.0

type ReplaceCommand struct {
	Mode KeyValueMode
	// contains filtered or unexported fields
}

ReplaceCommand container for all 'replace' parameters

func NewReplaceCommand added in v0.9.0

func NewReplaceCommand(c *client.Client) *ReplaceCommand

NewReplaceCommand creates a new ReplaceCommand parameter container

func (*ReplaceCommand) FindReplacements added in v0.9.0

func (cmd *ReplaceCommand) FindReplacements(search string, replacement string, path string) (matches []*Match, err error)

FindReplacements will find the matches for a given search string to be replaced

func (*ReplaceCommand) GetArgs added in v0.9.0

func (cmd *ReplaceCommand) GetArgs() interface{}

GetArgs provides the struct holding arguments for the command

func (*ReplaceCommand) GetName added in v0.9.0

func (cmd *ReplaceCommand) GetName() string

GetName returns the ReplaceCommand's name identifier

func (*ReplaceCommand) GetSearchParams added in v0.9.0

func (cmd *ReplaceCommand) GetSearchParams() SearchParameters

GetSearchParams returns the search parameters the command was run with

func (*ReplaceCommand) IsSane added in v0.9.0

func (cmd *ReplaceCommand) IsSane() bool

IsSane returns true if command is sane

func (*ReplaceCommand) Parse added in v0.9.0

func (cmd *ReplaceCommand) Parse(args []string) error

Parse given arguments and return status

func (*ReplaceCommand) PrintUsage added in v0.9.0

func (cmd *ReplaceCommand) PrintUsage()

PrintUsage print command usage

func (*ReplaceCommand) Run added in v0.9.0

func (cmd *ReplaceCommand) Run() int

Run executes 'replace' with given ReplaceCommand's parameters

func (*ReplaceCommand) WriteReplacements added in v0.9.0

func (cmd *ReplaceCommand) WriteReplacements(groupedMatches map[string][]*Match) error

WriteReplacements will write replacement data back to Vault

type ReplaceCommandArgs added in v0.9.0

type ReplaceCommandArgs struct {
	Search      string         `arg:"positional,required"`
	Replacement string         `arg:"positional,required"`
	Path        string         `arg:"positional"`
	Confirm     bool           `arg:"-y,--confirm" help:"Write results without prompt"`
	DryRun      bool           `arg:"-n,--dry-run" help:"Skip writing results without prompt"`
	KeySelector string         `arg:"-s,--key-selector" help:"Limit replacements to specified key" placeholder:"PATTERN"`
	Keys        bool           `arg:"-k,--keys" help:"Match against keys (true if -v is not specified)"`
	Output      MatchOutputArg `arg:"-o,--output" help:"Present changes as 'inline' with color or traditional 'diff'" default:"inline"`
	Regexp      bool           `arg:"-e,--regexp" help:"Treat search string and selector as a regexp"`
	Shallow     bool           `arg:"-S,--shallow" help:"Only search leaf nodes of the path rather than recurse deeper"`
	Values      bool           `arg:"-v,--values" help:"Match against values (true if -k is not specified)"`
}

ReplaceCommandArgs provides a struct for go-arg parsing

func (ReplaceCommandArgs) Description added in v0.9.0

func (ReplaceCommandArgs) Description() string

Description provides detail on what the command does

type SearchParameters added in v0.9.0

type SearchParameters struct {
	Search      string
	Replacement *string
	KeySelector string
	Mode        KeyValueMode
	IsRegexp    bool
	Output      MatchOutput
}

SearchParameters struct are parameters common to a command that performs a search operation

type Searcher added in v0.9.0

type Searcher struct {
	// contains filtered or unexported fields
}

Searcher provides matching and replacement methods while maintaining references to the command that provides an interface to search operations. Also maintains reference to a compiled regexp.

func NewSearcher added in v0.9.0

func NewSearcher(cmd SearchingCommand) (*Searcher, error)

NewSearcher creates a new Searcher container for performing search and optionally replace

func (*Searcher) DoSearch added in v0.9.0

func (s *Searcher) DoSearch(path string, k string, v string) (m []*Match)

DoSearch searches with either regexp or substring search methods

func (*Searcher) IsMode added in v0.9.0

func (s *Searcher) IsMode(mode KeyValueMode) bool

IsMode returns true if the specified mode is enabled

type SearchingCommand added in v0.9.0

type SearchingCommand interface {
	GetSearchParams() SearchParameters
}

SearchingCommand interface to describe a command that performs a search operation

Jump to

Keyboard shortcuts

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