diff --git a/src/cli/backup/backup.go b/src/cli/backup/backup.go new file mode 100644 index 000000000..270277125 --- /dev/null +++ b/src/cli/backup/backup.go @@ -0,0 +1,26 @@ +package backup + +import ( + "github.com/spf13/cobra" +) + +// AddCommands attaches all `corso backup * *` commands to the parent. +func AddCommands(parent *cobra.Command) { + parent.AddCommand(backupCmd) +} + +// The backup category of commands. +// `corso backup [] [...]` +var backupCmd = &cobra.Command{ + Use: "backup", + Short: "Backup your application data.", + Long: `Backup the data stored in one of your M365 applications.`, + Run: handleBackupCmd, + Args: cobra.NoArgs, +} + +// Handler for flat calls to `corso backup`. +// Produces the same output as `corso backup --help`. +func handleBackupCmd(cmd *cobra.Command, args []string) { + cmd.Help() +} diff --git a/src/cli/cli.go b/src/cli/cli.go index 6932b952f..99eb3a22a 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" + "github.com/alcionai/corso/cli/backup" "github.com/alcionai/corso/cli/repo" ) @@ -38,6 +39,7 @@ func Handle() { corsoCmd.Flags().BoolP("version", "v", version, "current version info") repo.AddCommands(corsoCmd) + backup.AddCommands(corsoCmd) if err := corsoCmd.Execute(); err != nil { fmt.Println(err) diff --git a/src/cli/repo/repo.go b/src/cli/repo/repo.go index ea53db890..42a0ae3d1 100644 --- a/src/cli/repo/repo.go +++ b/src/cli/repo/repo.go @@ -1,7 +1,6 @@ package repo import ( - "errors" "os" "github.com/spf13/cobra" @@ -86,14 +85,3 @@ func getM365Vars() m365Vars { tenantID: "todo:tenantID", } } - -// validates the existence of the properties in the map. -// expects a map[propName]propVal. -func requireProps(props map[string]string) error { - for name, val := range props { - if len(val) == 0 { - return errors.New(name + " is required to perform this command") - } - } - return nil -} diff --git a/src/cli/repo/s3.go b/src/cli/repo/s3.go index 10c85484a..584336774 100644 --- a/src/cli/repo/s3.go +++ b/src/cli/repo/s3.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" + "github.com/alcionai/corso/cli/utils" "github.com/alcionai/corso/pkg/repository" "github.com/alcionai/corso/pkg/storage" ) @@ -155,7 +156,7 @@ func makeS3Config() (storage.S3Config, storage.CommonConfig, error) { storage.CommonConfig{ CorsoPassword: corsoPasswd, }, - requireProps(map[string]string{ + utils.RequireProps(map[string]string{ storage.AWS_ACCESS_KEY_ID: ak, "bucket": bucket, storage.AWS_SECRET_ACCESS_KEY: secretKey, diff --git a/src/cli/utils/utils.go b/src/cli/utils/utils.go new file mode 100644 index 000000000..911d434aa --- /dev/null +++ b/src/cli/utils/utils.go @@ -0,0 +1,14 @@ +package utils + +import "errors" + +// RequireProps validates the existence of the properties +// in the map. Expects the format map[propName]propVal. +func RequireProps(props map[string]string) error { + for name, val := range props { + if len(val) == 0 { + return errors.New(name + " is required to perform this command") + } + } + return nil +} diff --git a/src/cli/repo/repo_test.go b/src/cli/utils/utils_test.go similarity index 63% rename from src/cli/repo/repo_test.go rename to src/cli/utils/utils_test.go index b16604497..09f56b305 100644 --- a/src/cli/repo/repo_test.go +++ b/src/cli/utils/utils_test.go @@ -1,21 +1,23 @@ -package repo +package utils_test import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" + + "github.com/alcionai/corso/cli/utils" ) -type CliRepoSuite struct { +type CliUtilsSuite struct { suite.Suite } -func TestCliRepoSuite(t *testing.T) { - suite.Run(t, new(CliRepoSuite)) +func TestCliUtilsSuite(t *testing.T) { + suite.Run(t, new(CliUtilsSuite)) } -func (suite *CliRepoSuite) TestRequireProps() { +func (suite *CliUtilsSuite) TestRequireProps() { table := []struct { name string props map[string]string @@ -31,6 +33,6 @@ func (suite *CliRepoSuite) TestRequireProps() { }, } for _, test := range table { - test.errCheck(suite.T(), requireProps(test.props)) + test.errCheck(suite.T(), utils.RequireProps(test.props)) } }