Add 'repo' cli command set (#31)

Adds the 'repo' command and its primary subcommands to the
Corso cli command list.
This commit is contained in:
Keepers 2022-05-09 16:15:07 -06:00 committed by GitHub
parent a352ddf8a1
commit 82c9a1f182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 0 deletions

View File

@ -5,6 +5,8 @@ import (
"os"
"github.com/spf13/cobra"
"github.com/alcionai/corso/cli/repo"
)
// The root-level command.
@ -34,6 +36,9 @@ func handleCorsoCmd(cmd *cobra.Command, args []string) {
// Handle builds and executes the cli processor.
func Handle() {
corsoCmd.Flags().BoolP("version", "v", version, "current version info")
repo.AddCommands(corsoCmd)
if err := corsoCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)

60
src/cli/repo/repo.go Normal file
View File

@ -0,0 +1,60 @@
package repo
import (
"github.com/spf13/cobra"
)
// AddCommands attaches all `corso repo * *` commands to the parent.
func AddCommands(parent *cobra.Command) {
parent.AddCommand(repoCmd)
repoCmd.AddCommand(initCmd)
repoCmd.AddCommand(connectCmd)
}
// The repo category of commands.
// `corso repo [<subcommand>] [<flag>...]`
var repoCmd = &cobra.Command{
Use: "repo",
Short: "Manage your repositories.",
Long: `Initialize, configure, and connect to your account backup repositories.`,
Run: 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) {
cmd.Help()
}
// The repo init subcommand.
// `corso repo init <repository> [<flag>...]`
var initCommand = "init"
var initCmd = &cobra.Command{
Use: initCommand,
Short: "Initialize a repository.",
Long: `Create a new repository to store your backups.`,
Run: handleInitCmd,
Args: cobra.NoArgs,
}
// Handler for calls to `corso repo init`.
func handleInitCmd(cmd *cobra.Command, args []string) {
cmd.Help()
}
// The repo connect subcommand.
// `corso repo connect <repository> [<flag>...]`
var connectCommand = "connect"
var connectCmd = &cobra.Command{
Use: connectCommand,
Short: "Connect to a repository.",
Long: `Connect to an existing repository.`,
Run: handleInitCmd,
Args: cobra.NoArgs,
}
// Handler for calls to `corso repo connect`.
func handleConnectCmd(cmd *cobra.Command, args []string) {
cmd.Help()
}