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:
parent
44392ab8b2
commit
8a9c1acc9e
26
src/cli/backup/backup.go
Normal file
26
src/cli/backup/backup.go
Normal 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()
|
||||
}
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
14
src/cli/utils/utils.go
Normal file
14
src/cli/utils/utils.go
Normal 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
|
||||
}
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user