Documentation ¶
Index ¶
- Constants
- type Arg
- type ArgModifier
- type ArgOption
- type ArgType
- type Args
- func (a *Args) AddArg(arg Arg)
- func (a *Args) AddArgs(args []Arg)
- func (a *Args) AddFlag(key string, arg Arg)
- func (a *Args) AddFlags(key string, args []Arg)
- func (a *Args) Clone() *Args
- func (a *Args) Get(name string) ([]Arg, bool)
- func (a *Args) GetAll() []string
- func (a *Args) Modify(modifier ArgModifier) *Args
- func (a *Args) Remove(name string) ([]Arg, bool)
- func (a *Args) RemoveArg(name string) (removed []Arg)
- func (a *Args) Rename(oldName, newName string) bool
- func (a *Args) ToMap() map[string][]string
- func (a *Args) Walk(callback func(name string, arg *Arg) *Arg)
- type Command
- type ConfidentialArgModifier
- type ConfidentialArgOption
- type EmptyArgOption
- type ExpandEnvModifier
- type LegacyArgModifier
- type OutputAnalyser
- func (a *OutputAnalyser) AnalyseLines(output io.Reader) (err error)
- func (a *OutputAnalyser) AnalyseStringLines(output string) error
- func (a *OutputAnalyser) ContainsRemoteLockFailure() bool
- func (a *OutputAnalyser) GetRemoteLockedBy() (string, bool)
- func (a *OutputAnalyser) GetRemoteLockedMaxWait() (time.Duration, bool)
- func (a *OutputAnalyser) GetRemoteLockedSince() (time.Duration, bool)
- func (a *OutputAnalyser) Reset() *OutputAnalyser
- func (a *OutputAnalyser) SetCallback(name, pattern string, minCount, maxCalls int, stopOnError bool, ...) error
- type ResticJsonSummary
- type ScanOutput
- type SetPID
Constants ¶
const ArgTypeCount = 4
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Arg ¶ added in v0.15.0
type Arg struct {
// contains filtered or unexported fields
}
func NewArgsSlice ¶ added in v0.28.0
func NewEmptyValueArg ¶ added in v0.23.0
func NewEmptyValueArg() Arg
func (Arg) GetConfidentialValue ¶ added in v0.28.0
func (Arg) HasConfidentialFilter ¶ added in v0.28.0
IsConfidential returns true if the argument may contain credentials.
func (Arg) HasValue ¶ added in v0.15.0
HasValue returns true if the argument has a value (e.g. --flag=value). The value could be empty (e.g. --flag=""). If false, the argument is a simple flag (e.g. --verbose).
func (Arg) IsEmptyValue ¶ added in v0.28.0
IsEmpty means the flag is specifically empty, not just a flag without a value (e.g. --flag="")
type ArgModifier ¶ added in v0.28.0
type ArgOption ¶ added in v0.28.0
type ArgOption interface {
// contains filtered or unexported methods
}
type ArgType ¶ added in v0.15.0
type ArgType int
const ( ArgConfigEscape ArgType = iota // escape each special character but don't add quotes ArgConfigKeepGlobQuote // use double quotes around argument when needed so the shell doesn't resolve glob patterns ArgCommandLineEscape // same as ArgConfigEscape but argument is coming from the command line ArgConfigBackupSource // same as ArgConfigEscape but represents the folders to add at the end of a backup command ArgLegacyEscape ArgLegacyKeepGlobQuote ArgLegacyCommandLineEscape ArgLegacyConfigBackupSource )
type Args ¶ added in v0.15.0
type Args struct {
// contains filtered or unexported fields
}
Args is a collection of arguments that can be used to build a command line.
func (*Args) GetAll ¶ added in v0.15.0
GetAll return a clean list of arguments to send on the command line
func (*Args) Modify ¶ added in v0.28.0
func (a *Args) Modify(modifier ArgModifier) *Args
Modify returns a new Args with all arguments modified by the provided modifier
type Command ¶
type Command struct { Command string Arguments []string Environ []string Shell []string Dir string Stdin io.Reader Stdout io.Writer Stderr io.Writer SetPID SetPID ScanStdout ScanOutput // contains filtered or unexported fields }
Command holds the configuration to run a shell command
func NewCommand ¶
NewCommand instantiate a default Command without receiving OS signals (SIGTERM, etc.)
func NewSignalledCommand ¶ added in v0.6.1
NewSignalledCommand instantiate a default Command receiving OS signals (SIGTERM, etc.)
func (*Command) GetShellCommand ¶ added in v0.18.0
GetShellCommand transforms the command line and arguments to be launched via a shell (sh or cmd.exe). This method doesn't escape any argument containing spaces, it should have been dealt with before.
type ConfidentialArgModifier ¶ added in v0.28.0
type ConfidentialArgModifier struct { }
ConfidentialArgModifier masks confidential information in arguments.
func NewConfidentialArgModifier ¶ added in v0.28.0
func NewConfidentialArgModifier() *ConfidentialArgModifier
type ConfidentialArgOption ¶ added in v0.28.0
type ConfidentialArgOption struct {
ConfidentialFilter filterFunc
}
func NewConfidentialArgOption ¶ added in v0.28.0
func NewConfidentialArgOption(confidential bool) *ConfidentialArgOption
type EmptyArgOption ¶ added in v0.28.0
type EmptyArgOption struct{}
EmptyArgOption is an option to create an specifically empty argument (e.g. --flag="")
type ExpandEnvModifier ¶ added in v0.28.0
type ExpandEnvModifier struct {
// contains filtered or unexported fields
}
func NewExpandEnvModifier ¶ added in v0.28.0
func NewExpandEnvModifier(environment []string) *ExpandEnvModifier
type LegacyArgModifier ¶ added in v0.28.0
type LegacyArgModifier struct {
// contains filtered or unexported fields
}
LegacyArgModifier changes the type of arguments to a legacy type.
func NewLegacyArgModifier ¶ added in v0.28.0
func NewLegacyArgModifier(legacy bool) *LegacyArgModifier
type OutputAnalyser ¶ added in v0.14.0
type OutputAnalyser struct {
// contains filtered or unexported fields
}
func NewOutputAnalyser ¶ added in v0.14.0
func NewOutputAnalyser() *OutputAnalyser
func (*OutputAnalyser) AnalyseLines ¶ added in v0.14.0
func (a *OutputAnalyser) AnalyseLines(output io.Reader) (err error)
func (*OutputAnalyser) AnalyseStringLines ¶ added in v0.14.0
func (a *OutputAnalyser) AnalyseStringLines(output string) error
func (*OutputAnalyser) ContainsRemoteLockFailure ¶ added in v0.14.0
func (a *OutputAnalyser) ContainsRemoteLockFailure() bool
func (*OutputAnalyser) GetRemoteLockedBy ¶ added in v0.14.0
func (a *OutputAnalyser) GetRemoteLockedBy() (string, bool)
func (*OutputAnalyser) GetRemoteLockedMaxWait ¶ added in v0.23.0
func (a *OutputAnalyser) GetRemoteLockedMaxWait() (time.Duration, bool)
func (*OutputAnalyser) GetRemoteLockedSince ¶ added in v0.14.0
func (a *OutputAnalyser) GetRemoteLockedSince() (time.Duration, bool)
func (*OutputAnalyser) Reset ¶ added in v0.17.0
func (a *OutputAnalyser) Reset() *OutputAnalyser
func (*OutputAnalyser) SetCallback ¶ added in v0.17.0
func (a *OutputAnalyser) SetCallback(name, pattern string, minCount, maxCalls int, stopOnError bool, callback func(line string) error) error
SetCallback registers a custom callback that is invoked when pattern (regex) matches a line.
type ResticJsonSummary ¶ added in v0.12.0
type ResticJsonSummary struct { MessageType string `json:"message_type"` FilesNew int `json:"files_new"` FilesChanged int `json:"files_changed"` FilesUnmodified int `json:"files_unmodified"` DirsNew int `json:"dirs_new"` DirsChanged int `json:"dirs_changed"` DirsUnmodified int `json:"dirs_unmodified"` DataBlobs int `json:"data_blobs"` TreeBlobs int `json:"tree_blobs"` DataAdded uint64 `json:"data_added"` TotalFilesProcessed int `json:"total_files_processed"` TotalBytesProcessed uint64 `json:"total_bytes_processed"` TotalDuration float64 `json:"total_duration"` SnapshotID string `json:"snapshot_id"` }
type ScanOutput ¶ added in v0.12.0
ScanOutput is a callback to scan the default output of the command The implementation is expected to send everything read from the reader back to the writer
var ScanBackupJson ScanOutput = func(r io.Reader, summary *monitor.Summary, w io.Writer) error { bogusPrefix := []byte("\r\x1b[2K") jsonPrefix := []byte(`{"message_type":"`) summaryPrefix := []byte(`{"message_type":"summary",`) jsonSuffix := []byte("}") eol := "\n" if runtime.GOOS == "windows" { eol = "\r\n" } scanner := bufio.NewScanner(r) for scanner.Scan() { line := scanner.Bytes() line = bytes.TrimPrefix(line, bogusPrefix) if bytes.HasPrefix(line, jsonPrefix) && bytes.HasSuffix(line, jsonSuffix) { if bytes.HasPrefix(line, summaryPrefix) { jsonSummary := ResticJsonSummary{} err := json.Unmarshal(line, &jsonSummary) if err != nil { continue } summary.FilesNew = jsonSummary.FilesNew summary.FilesChanged = jsonSummary.FilesChanged summary.FilesUnmodified = jsonSummary.FilesUnmodified summary.DirsNew = jsonSummary.DirsNew summary.DirsChanged = jsonSummary.DirsChanged summary.DirsUnmodified = jsonSummary.DirsUnmodified summary.FilesTotal = jsonSummary.TotalFilesProcessed summary.BytesAdded = jsonSummary.DataAdded summary.BytesTotal = jsonSummary.TotalBytesProcessed } continue } _, _ = w.Write(line) _, _ = w.Write([]byte(eol)) } if err := scanner.Err(); err != nil { return err } return nil }
ScanBackupJson should populate the backup summary values from the output of the --json flag
var ScanBackupPlain ScanOutput = func(r io.Reader, summary *monitor.Summary, w io.Writer) error { eol := "\n" if runtime.GOOS == "windows" { eol = "\r\n" } rawBytes, unit, duration := 0.0, "", "" scanner := bufio.NewScanner(r) for scanner.Scan() { _, err := w.Write([]byte(scanner.Text() + eol)) if err != nil { return err } _, _ = fmt.Sscanf(scanner.Text(), "Files: %d new, %d changed, %d unmodified", &summary.FilesNew, &summary.FilesChanged, &summary.FilesUnmodified) _, _ = fmt.Sscanf(scanner.Text(), "Dirs: %d new, %d changed, %d unmodified", &summary.DirsNew, &summary.DirsChanged, &summary.DirsUnmodified) n, err := fmt.Sscanf(scanner.Text(), "Added to the repo: %f %3s", &rawBytes, &unit) if n == 2 && err == nil { summary.BytesAdded = unformatBytes(rawBytes, unit) } n, err = fmt.Sscanf(scanner.Text(), "processed %d files, %f %3s in %s", &summary.FilesTotal, &rawBytes, &unit, &duration) if n == 4 && err == nil { summary.BytesTotal = unformatBytes(rawBytes, unit) } } if err := scanner.Err(); err != nil { return err } return nil }
ScanBackupPlain should populate the backup summary values from the standard output