Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Profile struct {
PrometheusSaveToFile string `mapstructure:"prometheus-save-to-file"`
PrometheusPush string `mapstructure:"prometheus-push"`
PrometheusLabels map[string]string `mapstructure:"prometheus-labels"`
DefaultCommand string `mapstructure:"default-command"`
OtherFlags map[string]interface{} `mapstructure:",remain"`
Environment map[string]ConfidentialValue `mapstructure:"env"`
Backup *BackupSection `mapstructure:"backup"`
Expand Down
33 changes: 24 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,30 @@

// The remaining arguments are going to be sent to the restic command line
resticArguments := flags.resticArgs
resticCommand := global.DefaultCommand
if len(resticArguments) > 0 {
resticCommand = resticArguments[0]
resticArguments = resticArguments[1:]
}
resticCommand := func() func(profile string) string {
if len(resticArguments) > 0 {
command := resticArguments[0]
resticArguments = resticArguments[1:]

Check warning on line 199 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L196-L199

Added lines #L196 - L199 were not covered by tests
// Command specified in arguments list
return func(profile string) string {
return command

Check warning on line 202 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L201-L202

Added lines #L201 - L202 were not covered by tests
}
} else {

Check warning on line 204 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L204

Added line #L204 was not covered by tests
// Default command (as defined in global or profile)
return func(profile string) string {
if c.HasProfile(profile) {
if p, err := c.GetProfile(profile); err == nil && p.DefaultCommand != "" {
return p.DefaultCommand

Check warning on line 209 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L206-L209

Added lines #L206 - L209 were not covered by tests
}
}
return global.DefaultCommand

Check warning on line 212 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L212

Added line #L212 was not covered by tests
}
}
}()

// resticprofile own commands (with configuration file)
if isOwnCommand(resticCommand, true) {
err = runOwnCommand(c, resticCommand, flags, resticArguments)
if isOwnCommand(resticCommand(flags.name), true) {
err = runOwnCommand(c, resticCommand(flags.name), flags, resticArguments)

Check warning on line 219 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L218-L219

Added lines #L218 - L219 were not covered by tests
if err != nil {
clog.Error(err)
exitCode = 1
Expand All @@ -216,7 +231,7 @@
defer notifyStop()

// Single profile run
err = runProfile(c, global, flags, flags.name, resticBinary, resticArguments, resticCommand, "")
err = runProfile(c, global, flags, flags.name, resticBinary, resticArguments, resticCommand(flags.name), "")

Check warning on line 234 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L234

Added line #L234 was not covered by tests
if err != nil {
clog.Error(err)
exitCode = 1
Expand All @@ -236,7 +251,7 @@

for i, profileName := range group {
clog.Debugf("[%d/%d] starting profile '%s' from group '%s'", i+1, len(group), profileName, flags.name)
err = runProfile(c, global, flags, profileName, resticBinary, resticArguments, resticCommand, flags.name)
err = runProfile(c, global, flags, profileName, resticBinary, resticArguments, resticCommand(profileName), flags.name)

Check warning on line 254 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L254

Added line #L254 was not covered by tests
if err != nil {
clog.Error(err)
exitCode = 1
Expand Down