Skip to content

Commit

Permalink
Format bool arguments in a way it expected by kopia's cmd lib. (#1849)
Browse files Browse the repository at this point in the history
* Format bool arguments in a way it expected by kopia's cmd lib. See https://github.com/alecthomas/kingpin/blob/master/README.md#boolean-values

* Add dashes to func's description to describe the k[2:] behaviour

* Implement simple version of check

* Revert changes

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
TimonOmsk and mergify[bot] authored Jan 9, 2023
1 parent 15157fb commit 48f08e1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/kopia/command/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
ownerFlag = "--owner"
sparseFlag = "--write-sparse-files"
ignorePermissionsError = "--ignore-permission-errors"
noIgnorePermissionsError = "--no-ignore-permission-errors"

// Server specific
addSubCommand = "add"
Expand Down
8 changes: 5 additions & 3 deletions pkg/kopia/command/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package command

import "strconv"

type RestoreCommandArgs struct {
*CommandArgs
RootID string
Expand All @@ -27,7 +25,11 @@ type RestoreCommandArgs struct {
func Restore(cmdArgs RestoreCommandArgs) []string {
args := commonArgs(cmdArgs.CommandArgs, false)
args = args.AppendLoggable(restoreSubCommand, cmdArgs.RootID, cmdArgs.TargetPath)
args = args.AppendLoggableKV(ignorePermissionsError, strconv.FormatBool(cmdArgs.IgnorePermissionErrors))
if cmdArgs.IgnorePermissionErrors {
args = args.AppendLoggable(ignorePermissionsError)
} else {
args = args.AppendLoggable(noIgnorePermissionsError)
}

return stringSliceCommand(args)
}
4 changes: 2 additions & 2 deletions pkg/kopia/command/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (kRestore *KopiaRestoreTestSuite) TestRestoreCommands(c *C) {
}
return Restore(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key restore snapshot-id target/path --ignore-permission-errors=false",
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key restore snapshot-id target/path --no-ignore-permission-errors",
},
{
f: func() []string {
Expand All @@ -58,7 +58,7 @@ func (kRestore *KopiaRestoreTestSuite) TestRestoreCommands(c *C) {
}
return Restore(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key restore snapshot-id target/path --ignore-permission-errors=true",
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key restore snapshot-id target/path --ignore-permission-errors",
},
} {
cmd := strings.Join(tc.f(), " ")
Expand Down
6 changes: 5 additions & 1 deletion pkg/kopia/command/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ type SnapshotRestoreCommandArgs struct {
func SnapshotRestore(cmdArgs SnapshotRestoreCommandArgs) []string {
args := commonArgs(cmdArgs.CommandArgs, false)
args = args.AppendLoggable(snapshotSubCommand, restoreSubCommand, cmdArgs.SnapID, cmdArgs.TargetPath)
args = args.AppendLoggableKV(ignorePermissionsError, strconv.FormatBool(cmdArgs.IgnorePermissionErrors))
if cmdArgs.IgnorePermissionErrors {
args = args.AppendLoggable(ignorePermissionsError)
} else {
args = args.AppendLoggable(noIgnorePermissionsError)
}
if cmdArgs.SparseRestore {
args = args.AppendLoggable(sparseFlag)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kopia/command/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (kSnapshot *KopiaSnapshotTestSuite) TestSnapshotCommands(c *C) {
}
return SnapshotRestore(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --ignore-permission-errors=false",
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --no-ignore-permission-errors",
},
{
f: func() []string {
Expand All @@ -91,7 +91,7 @@ func (kSnapshot *KopiaSnapshotTestSuite) TestSnapshotCommands(c *C) {
}
return SnapshotRestore(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --ignore-permission-errors=false",
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --no-ignore-permission-errors",
},
{
f: func() []string {
Expand All @@ -104,7 +104,7 @@ func (kSnapshot *KopiaSnapshotTestSuite) TestSnapshotCommands(c *C) {
}
return SnapshotRestore(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --ignore-permission-errors=true --write-sparse-files",
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --ignore-permission-errors --write-sparse-files",
},
{
f: func() []string {
Expand Down

0 comments on commit 48f08e1

Please sign in to comment.