Skip to content

Commit 68c0331

Browse files
committed
renamed "log-commands" to "command-output"
1 parent 69154f8 commit 68c0331

File tree

11 files changed

+47
-43
lines changed

11 files changed

+47
-43
lines changed

commands.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ func prepareScheduledProfile(ctx *Context) {
626626
if len(s.Log) > 0 {
627627
ctx.logTarget = s.Log
628628
}
629-
if len(s.LogCommands) > 0 {
630-
ctx.logCommands = s.LogCommands
629+
if len(s.CommandOutput) > 0 {
630+
ctx.commandOutput = s.CommandOutput
631631
}
632632
// battery
633633
if s.IgnoreOnBatteryLessThan > 0 && !s.IgnoreOnBattery.IsStrictlyFalse() {

commands_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,15 @@ func TestShowSchedules(t *testing.T) {
288288
schedule backup@default:
289289
at: daily
290290
permission: auto
291-
log-commands: auto
291+
command-output: auto
292292
priority: background
293293
lock-mode: default
294294
capture-environment: RESTIC_*
295295
296296
schedule check@default:
297297
at: weekly
298298
permission: auto
299-
log-commands: auto
299+
command-output: auto
300300
priority: background
301301
lock-mode: default
302302
capture-environment: RESTIC_*

complete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func (c *Completer) completeFlagSetValue(flag *pflag.Flag, word string) (complet
115115
fallthrough
116116
case "log":
117117
completions = []string{RequestFileCompletion}
118-
case "log-commands":
119-
completions = []string{"auto", "log", "console", "both"}
118+
case "command-output":
119+
completions = []string{"auto", "log", "console", "all"}
120120
}
121121

122122
completions = c.appendMatches(completions, word, list...)

config/global.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Global struct {
2727
Scheduler string `mapstructure:"scheduler" description:"Leave blank for the default scheduler or use \"crond\" to select cron on supported operating systems"`
2828
ScheduleDefaults *ScheduleBaseConfig `mapstructure:"schedule-defaults" default:"" description:"Sets defaults for all schedules"`
2929
Log string `mapstructure:"log" default:"" examples:"/resticprofile.log;syslog-tcp://syslog-server:514;syslog:server;syslog:" description:"Sets the default log destination to be used if not specified in \"--log\" or \"schedule-log\" - see https://creativeprojects.github.io/resticprofile/configuration/logs/"`
30-
LogCommands string `mapstructure:"log-commands" default:"auto" enum:"auto;log;console;both" description:"Sets the destination for command output (stderr/stdout). \"log\" sends output to the log file (if specified), \"console\" sends it to the console instead. \"auto\" sends it to \"both\" if console is a terminal otherwise to \"log\" only - see https://creativeprojects.github.io/resticprofile/configuration/logs/"`
30+
CommandOutput string `mapstructure:"command-output" default:"auto" enum:"auto;log;console;all" description:"Sets the destination for command output (stderr/stdout). \"log\" sends output to the log file (if specified), \"console\" sends it to the console instead. \"auto\" sends it to \"both\" if console is a terminal otherwise to \"log\" only - see https://creativeprojects.github.io/resticprofile/configuration/logs/"`
3131
LegacyArguments bool `mapstructure:"legacy-arguments" default:"false" deprecated:"0.20.0" description:"Legacy, broken arguments mode of resticprofile before version 0.15"`
3232
SystemdUnitTemplate string `mapstructure:"systemd-unit-template" default:"" description:"File containing the go template to generate a systemd unit - see https://creativeprojects.github.io/resticprofile/schedules/systemd/"`
3333
SystemdTimerTemplate string `mapstructure:"systemd-timer-template" default:"" description:"File containing the go template to generate a systemd timer - see https://creativeprojects.github.io/resticprofile/schedules/systemd/"`
@@ -48,7 +48,7 @@ func NewGlobal() *Global {
4848
ResticLockRetryAfter: constants.DefaultResticLockRetryAfter,
4949
ResticStaleLockAge: constants.DefaultResticStaleLockAge,
5050
MinMemory: constants.DefaultMinMemory,
51-
LogCommands: constants.DefaultLogCommands,
51+
CommandOutput: constants.DefaultCommandOutput,
5252
SenderTimeout: constants.DefaultSenderTimeout,
5353
}
5454
}

config/schedule.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const (
3636
type ScheduleBaseConfig struct {
3737
Permission string `mapstructure:"permission" default:"auto" enum:"auto;system;user;user_logged_on" description:"Specify whether the schedule runs with system or user privileges - see https://creativeprojects.github.io/resticprofile/schedules/configuration/"`
3838
Log string `mapstructure:"log" examples:"/resticprofile.log;syslog-tcp://syslog-server:514;syslog:server;syslog:" description:"Redirect the output into a log file or to syslog when running on schedule - see https://creativeprojects.github.io/resticprofile/configuration/logs/"`
39-
LogCommands string `mapstructure:"log-commands" default:"auto" enum:"auto;log;console;both" description:"Sets the destination for command output (stderr/stdout). \"log\" sends output to the log file (if specified), \"console\" sends it to the console instead. \"auto\" sends it to \"both\" if console is a terminal otherwise to \"log\" only - see https://creativeprojects.github.io/resticprofile/configuration/logs/"`
39+
CommandOutput string `mapstructure:"command-output" default:"auto" enum:"auto;log;console;all" description:"Sets the destination for command output (stderr/stdout). \"log\" sends output to the log file (if specified), \"console\" sends it to the console instead. \"auto\" sends it to \"both\" if console is a terminal otherwise to \"log\" only - see https://creativeprojects.github.io/resticprofile/configuration/logs/"`
4040
Priority string `mapstructure:"priority" default:"background" enum:"background;standard" description:"Set the priority at which the schedule is run"`
4141
LockMode string `mapstructure:"lock-mode" default:"default" enum:"default;fail;ignore" description:"Specify how locks are used when running on schedule - see https://creativeprojects.github.io/resticprofile/schedules/configuration/"`
4242
LockWait maybe.Duration `mapstructure:"lock-wait" examples:"150s;15m;30m;45m;1h;2h30m" description:"Set the maximum time to wait for acquiring locks when running on schedule"`
@@ -49,11 +49,11 @@ type ScheduleBaseConfig struct {
4949

5050
// scheduleBaseConfigDefaults declares built-in scheduling defaults
5151
var scheduleBaseConfigDefaults = ScheduleBaseConfig{
52-
Permission: "auto",
53-
LogCommands: constants.DefaultLogCommands,
54-
Priority: "background",
55-
LockMode: "default",
56-
EnvCapture: []string{"RESTIC_*"},
52+
Permission: "auto",
53+
CommandOutput: constants.DefaultCommandOutput,
54+
Priority: "background",
55+
LockMode: "default",
56+
EnvCapture: []string{"RESTIC_*"},
5757
}
5858

5959
func (s *ScheduleBaseConfig) init(defaults *ScheduleBaseConfig) {
@@ -67,8 +67,8 @@ func (s *ScheduleBaseConfig) init(defaults *ScheduleBaseConfig) {
6767
if s.Log == "" {
6868
s.Log = defaults.Log
6969
}
70-
if s.LogCommands == "" {
71-
s.LogCommands = defaults.LogCommands
70+
if s.CommandOutput == "" {
71+
s.CommandOutput = defaults.CommandOutput
7272
}
7373
if s.Priority == "" {
7474
s.Priority = defaults.Priority

constants/default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818
DefaultVerboseFlag = false
1919
DefaultQuietFlag = false
2020
DefaultMinMemory = 100
21-
DefaultLogCommands = "auto"
21+
DefaultCommandOutput = "auto"
2222
DefaultSenderTimeout = 30 * time.Second
2323
DefaultPrometheusPushFormat = "text"
2424
BatteryFull = 100

context.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Context struct {
2929
schedule *config.Schedule // when profile is running with run-schedule command
3030
sigChan chan os.Signal // termination request
3131
logTarget string // where to send the log output
32-
logCommands string // where to send the command output when a lotTarget is set
32+
commandOutput string // where to send the command output when a lotTarget is set
3333
stopOnBattery int // stop if running on battery
3434
noLock bool // skip profile lock file
3535
lockWait time.Duration // wait up to duration to acquire a lock
@@ -52,16 +52,16 @@ func CreateContext(flags commandLineFlags, global *config.Global, cfg *config.Co
5252
group: "",
5353
schedule: "",
5454
},
55-
flags: flags,
56-
global: global,
57-
config: cfg,
58-
binary: "",
59-
command: "",
60-
profile: nil,
61-
schedule: nil,
62-
sigChan: nil,
63-
logTarget: global.Log, // default to global (which can be empty)
64-
logCommands: global.LogCommands,
55+
flags: flags,
56+
global: global,
57+
config: cfg,
58+
binary: "",
59+
command: "",
60+
profile: nil,
61+
schedule: nil,
62+
sigChan: nil,
63+
logTarget: global.Log, // default to global (which can be empty)
64+
commandOutput: global.CommandOutput,
6565
}
6666
// own commands can check the context before running
6767
if ownCommands.Exists(command, true) {
@@ -74,8 +74,8 @@ func CreateContext(flags commandLineFlags, global *config.Global, cfg *config.Co
7474
if flags.log != "" {
7575
ctx.logTarget = flags.log
7676
}
77-
if flags.logCommands != "" {
78-
ctx.logCommands = flags.logCommands
77+
if flags.commandOutput != "" {
78+
ctx.commandOutput = flags.commandOutput
7979
}
8080
// same for battery configuration
8181
if flags.ignoreOnBattery > 0 {

flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type commandLineFlags struct {
2424
format string
2525
name string
2626
log string // file path or log url
27-
logCommands string
27+
commandOutput string
2828
dryRun bool
2929
noLock bool
3030
lockWait time.Duration
@@ -81,7 +81,7 @@ func loadFlags(args []string) (*pflag.FlagSet, commandLineFlags, error) {
8181
format: envValueOverride("", "RESTICPROFILE_FORMAT"),
8282
name: envValueOverride(constants.DefaultProfileName, "RESTICPROFILE_NAME"),
8383
log: envValueOverride("", "RESTICPROFILE_LOG"),
84-
logCommands: envValueOverride(constants.DefaultLogCommands, "RESTICPROFILE_LOG_COMMANDS"),
84+
commandOutput: envValueOverride(constants.DefaultCommandOutput, "RESTICPROFILE_COMMAND_OUTPUT"),
8585
dryRun: envValueOverride(false, "RESTICPROFILE_DRY_RUN"),
8686
noLock: envValueOverride(false, "RESTICPROFILE_NO_LOCK"),
8787
lockWait: envValueOverride(time.Duration(0), "RESTICPROFILE_LOCK_WAIT"),
@@ -100,7 +100,7 @@ func loadFlags(args []string) (*pflag.FlagSet, commandLineFlags, error) {
100100
flagset.StringVarP(&flags.format, "format", "f", flags.format, "file format of the configuration (default is to use the file extension)")
101101
flagset.StringVarP(&flags.name, "name", "n", flags.name, "profile name")
102102
flagset.StringVarP(&flags.log, "log", "l", flags.log, "logs to a target instead of the console")
103-
flagset.StringVar(&flags.logCommands, "log-commands", flags.logCommands, "sets how to log command output when a log target is specified (auto, log, console, both)")
103+
flagset.StringVar(&flags.commandOutput, "command-output", flags.commandOutput, "sets how to redirect command output when a log target is specified (auto, log, console, all)")
104104
flagset.BoolVar(&flags.dryRun, "dry-run", flags.dryRun, "display the restic commands instead of running them")
105105
flagset.BoolVar(&flags.noLock, "no-lock", flags.noLock, "skip profile lock file")
106106
flagset.DurationVar(&flags.lockWait, "lock-wait", flags.lockWait, "wait up to duration to acquire a lock (syntax \"1h5m30s\")")

flags_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestEnvOverrides(t *testing.T) {
6565
format: setEnv("custom-format", "RESTICPROFILE_FORMAT").(string),
6666
name: setEnv("custom-profile", "RESTICPROFILE_NAME").(string),
6767
log: setEnv("custom.log", "RESTICPROFILE_LOG").(string),
68-
logCommands: setEnv("log", "RESTICPROFILE_LOG_COMMANDS").(string),
68+
commandOutput: setEnv("log", "RESTICPROFILE_COMMAND_OUTPUT").(string),
6969
dryRun: setEnv(true, "RESTICPROFILE_DRY_RUN").(bool),
7070
noLock: setEnv(true, "RESTICPROFILE_NO_LOCK").(bool),
7171
lockWait: setEnv(time.Minute*5, "RESTICPROFILE_LOCK_WAIT").(time.Duration),

logger.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log"
66
"os"
77
"path/filepath"
8+
"slices"
89
"strings"
910
"time"
1011

@@ -15,6 +16,7 @@ import (
1516
"github.com/creativeprojects/resticprofile/remote"
1617
"github.com/creativeprojects/resticprofile/term"
1718
"github.com/creativeprojects/resticprofile/util"
19+
"github.com/creativeprojects/resticprofile/util/collect"
1820
)
1921

2022
type LogCloser interface {
@@ -40,7 +42,7 @@ func setupRemoteLogger(flags commandLineFlags, client *remote.Client) {
4042
clog.SetDefaultLogger(logger)
4143
}
4244

43-
func setupTargetLogger(flags commandLineFlags, logTarget, logCommands string) (io.Closer, error) {
45+
func setupTargetLogger(flags commandLineFlags, logTarget, commandOutput string) (io.Closer, error) {
4446
var (
4547
handler LogCloser
4648
file io.Writer
@@ -62,17 +64,19 @@ func setupTargetLogger(flags commandLineFlags, logTarget, logCommands string) (i
6264

6365
// also redirect all terminal output
6466
if file != nil {
65-
if logCommands == "auto" {
67+
if commandOutput == "auto" {
6668
if term.OsStdoutIsTerminal() {
67-
logCommands = "both"
69+
commandOutput = "log,console"
6870
} else {
69-
logCommands = "log"
71+
commandOutput = "log"
7072
}
7173
}
72-
if logCommands == "both" {
74+
co := collect.From(strings.Split(commandOutput, ","), strings.TrimSpace)
75+
all := slices.Contains(co, "all") || (slices.Contains(co, "log") && slices.Contains(co, "console"))
76+
if all {
7377
term.SetOutput(io.MultiWriter(file, term.GetOutput()))
7478
term.SetErrorOutput(io.MultiWriter(file, term.GetErrorOutput()))
75-
} else if logCommands == "log" {
79+
} else if slices.Contains(co, "log") {
7680
term.SetAllOutput(file)
7781
}
7882
}

0 commit comments

Comments
 (0)