Skip to content

Commit

Permalink
Add kopia CLI repository status command
Browse files Browse the repository at this point in the history
  • Loading branch information
plar committed Feb 7, 2024
1 parent c5da317 commit eec4a16
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/kopia/cli/internal/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
Connect = Command{"connect"}
Server = Command{"server"}
SetParameters = Command{"set-parameters"}
Status = Command{"status"}
)

// Repository storage sub commands.
Expand Down
42 changes: 42 additions & 0 deletions pkg/kopia/cli/repository/repository_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2024 The Kanister Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package repository

import (
"github.com/kanisterio/safecli"

"github.com/kanisterio/kanister/pkg/log"

"github.com/kanisterio/kanister/pkg/kopia/cli"
"github.com/kanisterio/kanister/pkg/kopia/cli/internal/command"
flagcommon "github.com/kanisterio/kanister/pkg/kopia/cli/internal/flag/common"
)

// StatusArgs defines the arguments for the `kopia repository status ...` command.
type StatusArgs struct {
cli.CommonArgs

JSONOutput bool // shows the output in JSON format

Logger log.Logger
}

// Status creates a new `kopia repository status ...` command.
func Status(args StatusArgs) (safecli.CommandBuilder, error) {
return command.NewKopiaCommandBuilder(args.CommonArgs,
command.Repository, command.Status,
flagcommon.JSONOutput(args.JSONOutput),
)
}
40 changes: 40 additions & 0 deletions pkg/kopia/cli/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,43 @@ var _ = check.Suite(test.NewCommandSuite([]test.CommandTest{
},
},
}))

// Test Repository Status command
var _ = check.Suite(test.NewCommandSuite([]test.CommandTest{
{
Name: "repository status with default args",
CLI: func() (safecli.CommandBuilder, error) {
args := StatusArgs{
CommonArgs: test.CommonArgs,
}
return Status(args)
},
ExpectedCLI: []string{"kopia",
"--config-file=path/kopia.config",
"--log-level=error",
"--log-dir=cache/log",
"--password=encr-key",
"repository",
"status",
},
},
{
Name: "repository status with JSON output",
CLI: func() (safecli.CommandBuilder, error) {
args := StatusArgs{
CommonArgs: test.CommonArgs,
JSONOutput: true,
}
return Status(args)
},
ExpectedCLI: []string{"kopia",
"--config-file=path/kopia.config",
"--log-level=error",
"--log-dir=cache/log",
"--password=encr-key",
"repository",
"status",
"--json",
},
},
}))

0 comments on commit eec4a16

Please sign in to comment.