corso/src/cli/repo/repo.go
ashmrtn dd34ecd5f7
Test CLI init/connect and without s3 prefix on bucket (#1033)
## Description

Regression test for bucket prefix trimming

## Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [x] 🤖 Test
- [ ] 💻 CI/Deployment
- [ ] 🐹 Trivial/Minor

## Issue(s)

* #913 
* #975 

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
2022-10-04 16:45:09 +00:00

87 lines
2.0 KiB
Go

package repo
import (
"github.com/spf13/cobra"
)
const (
initCommand = "init"
connectCommand = "connect"
)
var repoCommands = []func(parent *cobra.Command) *cobra.Command{
addS3Commands,
}
// AddCommands attaches all `corso repo * *` commands to the parent.
func AddCommands(parent *cobra.Command) {
var (
// Get new instances so that setting the context during tests works
// properly.
repoCmd = repoCmd()
initCmd = initCmd()
connectCmd = connectCmd()
)
parent.AddCommand(repoCmd)
repoCmd.AddCommand(initCmd)
repoCmd.AddCommand(connectCmd)
for _, addRepoTo := range repoCommands {
addRepoTo(initCmd)
addRepoTo(connectCmd)
}
}
// The repo category of commands.
// `corso repo [<subcommand>] [<flag>...]`
func repoCmd() *cobra.Command {
return &cobra.Command{
Use: "repo",
Short: "Manage your repositories",
Long: `Initialize, configure, and connect to your account backup repositories.`,
RunE: handleRepoCmd,
Args: cobra.NoArgs,
}
}
// Handler for flat calls to `corso repo`.
// Produces the same output as `corso repo --help`.
func handleRepoCmd(cmd *cobra.Command, args []string) error {
return cmd.Help()
}
// The repo init subcommand.
// `corso repo init <repository> [<flag>...]`
func initCmd() *cobra.Command {
return &cobra.Command{
Use: initCommand,
Short: "Initialize a repository.",
Long: `Create a new repository to store your backups.`,
RunE: handleInitCmd,
Args: cobra.NoArgs,
}
}
// Handler for calls to `corso repo init`.
func handleInitCmd(cmd *cobra.Command, args []string) error {
return cmd.Help()
}
// The repo connect subcommand.
// `corso repo connect <repository> [<flag>...]`
func connectCmd() *cobra.Command {
return &cobra.Command{
Use: connectCommand,
Short: "Connect to a repository.",
Long: `Connect to an existing repository.`,
RunE: handleConnectCmd,
Args: cobra.NoArgs,
}
}
// Handler for calls to `corso repo connect`.
func handleConnectCmd(cmd *cobra.Command, args []string) error {
return cmd.Help()
}