add cli backup command (#142)

* add cli backup command

adds the `corso backup` command to the cli.  Currently
only displays the backup help.

* add backup to cli cmds, fix verbiage
This commit is contained in:
Keepers 2022-06-06 14:08:34 -06:00 committed by GitHub
parent 44392ab8b2
commit 8a9c1acc9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 19 deletions

26
src/cli/backup/backup.go Normal file
View File

@ -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 [<subcommand>] [<flag>...]`
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()
}

View File

@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/alcionai/corso/cli/backup"
"github.com/alcionai/corso/cli/repo" "github.com/alcionai/corso/cli/repo"
) )
@ -38,6 +39,7 @@ func Handle() {
corsoCmd.Flags().BoolP("version", "v", version, "current version info") corsoCmd.Flags().BoolP("version", "v", version, "current version info")
repo.AddCommands(corsoCmd) repo.AddCommands(corsoCmd)
backup.AddCommands(corsoCmd)
if err := corsoCmd.Execute(); err != nil { if err := corsoCmd.Execute(); err != nil {
fmt.Println(err) fmt.Println(err)

View File

@ -1,7 +1,6 @@
package repo package repo
import ( import (
"errors"
"os" "os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -86,14 +85,3 @@ func getM365Vars() m365Vars {
tenantID: "todo:tenantID", 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
}

View File

@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/alcionai/corso/cli/utils"
"github.com/alcionai/corso/pkg/repository" "github.com/alcionai/corso/pkg/repository"
"github.com/alcionai/corso/pkg/storage" "github.com/alcionai/corso/pkg/storage"
) )
@ -155,7 +156,7 @@ func makeS3Config() (storage.S3Config, storage.CommonConfig, error) {
storage.CommonConfig{ storage.CommonConfig{
CorsoPassword: corsoPasswd, CorsoPassword: corsoPasswd,
}, },
requireProps(map[string]string{ utils.RequireProps(map[string]string{
storage.AWS_ACCESS_KEY_ID: ak, storage.AWS_ACCESS_KEY_ID: ak,
"bucket": bucket, "bucket": bucket,
storage.AWS_SECRET_ACCESS_KEY: secretKey, storage.AWS_SECRET_ACCESS_KEY: secretKey,

14
src/cli/utils/utils.go Normal file
View File

@ -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
}

View File

@ -1,21 +1,23 @@
package repo package utils_test
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/cli/utils"
) )
type CliRepoSuite struct { type CliUtilsSuite struct {
suite.Suite suite.Suite
} }
func TestCliRepoSuite(t *testing.T) { func TestCliUtilsSuite(t *testing.T) {
suite.Run(t, new(CliRepoSuite)) suite.Run(t, new(CliUtilsSuite))
} }
func (suite *CliRepoSuite) TestRequireProps() { func (suite *CliUtilsSuite) TestRequireProps() {
table := []struct { table := []struct {
name string name string
props map[string]string props map[string]string
@ -31,6 +33,6 @@ func (suite *CliRepoSuite) TestRequireProps() {
}, },
} }
for _, test := range table { for _, test := range table {
test.errCheck(suite.T(), requireProps(test.props)) test.errCheck(suite.T(), utils.RequireProps(test.props))
} }
} }