Skip to content

Commit

Permalink
Add JSON output flag to kopia repo status command (#2109)
Browse files Browse the repository at this point in the history
Add the option to generate the kopia repo status command with JSON
output.
  • Loading branch information
redgoat650 committed Jun 14, 2023
1 parent 884b8cb commit 69af1af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/kopia/command/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func RepositoryConnectServerCommand(cmdArgs RepositoryServerCommandArgs) []strin

type RepositoryStatusCommandArgs struct {
*CommandArgs
GetJsonOutput bool
}

// RepositoryStatusCommand returns the kopia command for checking status of the Kopia repository
Expand All @@ -151,5 +152,9 @@ func RepositoryStatusCommand(cmdArgs RepositoryStatusCommandArgs) []string {

args := commonArgs(cmdArgs.CommandArgs)
args = args.AppendLoggable(repositorySubCommand, statusSubCommand)
if cmdArgs.GetJsonOutput {
args = args.AppendLoggable(jsonFlag)
}

return stringSliceCommand(args)
}
13 changes: 13 additions & 0 deletions pkg/kopia/command/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ func (kRepoStatus *RepositoryUtilsSuite) TestRepositoryStatusCommand(c *check.C)
},
expectedLog: "kopia --log-level=info --config-file=path/kopia.config --log-dir=cache/log repository status",
},
{
f: func() []string {
args := RepositoryStatusCommandArgs{
CommandArgs: &CommandArgs{
ConfigFilePath: "path/kopia.config",
LogDirectory: "cache/log",
},
GetJsonOutput: true,
}
return RepositoryStatusCommand(args)
},
expectedLog: "kopia --log-level=info --config-file=path/kopia.config --log-dir=cache/log repository status --json",
},
} {
cmd := strings.Join(tc.f(), " ")
c.Check(cmd, check.Equals, tc.expectedLog)
Expand Down

0 comments on commit 69af1af

Please sign in to comment.