Go version: Mutually exclusive flags check not working
FluffyEscargot opened this issue · 0 comments
Expected Behavior
Supplying just the --cron
flag or just the --once
flag should work.
Current Behavior
mysql-backup exits with errors depending on the flag
ERRO[0000] error creating timer: option 'Cron' is exclusive and must not be used with Begin, Once or Frequency
ERRO[0000] error creating timer: option 'Once' is exclusive and must not be used with Begin, Cron or Frequency
Steps to Reproduce
on master branch:
./mysql-backup dump --target /backup --cron "0 0 * * *"
./mysql-backup dump --target /backup --once
via docker:
docker run -e DB_DUMP_TARGET=/backup -e DB_DUMP_CRON="0 0 * * *" databack/mysql-backup:1.0.0-rc2 dump
docker run -e DB_DUMP_TARGET=/backup -e DB_DUMP_ONCE=true databack/mysql-backup:1.0.0-rc2 dump
Possible Solution
The --begin
and --frequency
flags have defaults (+0
and 1440
) which are loaded at the time when mutually exclusive flags are checked. Instead, check if both flags are set, before defaults are loaded.
Possible Implementation
cmd/dump.go:229 add:
cmd.MarkFlagsMutuallyExclusive("once", "cron")
cmd.MarkFlagsMutuallyExclusive("once", "begin")
cmd.MarkFlagsMutuallyExclusive("once", "frequency")
cmd.MarkFlagsMutuallyExclusive("cron", "begin")
cmd.MarkFlagsMutuallyExclusive("cron", "frequency")
pkg/core/timer.go:44 remove:
// validate we do not have conflicting options
if opts.Once && (opts.Cron != "" || opts.Begin != "" || opts.Frequency != 0) {
return nil, errors.New("option 'Once' is exclusive and must not be used with Begin, Cron or Frequency")
}
if opts.Cron != "" && (opts.Begin != "" || opts.Frequency != 0) {
return nil, errors.New("option 'Cron' is exclusive and must not be used with Begin, Once or Frequency")
}