corso/src/cli/backup/backup.go
Keepers 7e2fbbea4f
adds sharepoint restore cli commands (#1637)
## Description

Adds restore commands to the cli for sharepoint.
The restore process is only partially functional at this time.
Library files that pass auth are able to be restored as expected.
However, auth issues (not directly related to these changes) prevent
restoration of all library items at this time.

## Type of change

- [x] 🌻 Feature

## Issue(s)

* #1615

## Test Plan

- [x] 💪 Manual
- [x] 💚 E2E
2022-12-06 17:00:37 +00:00

128 lines
3.0 KiB
Go

package backup
import (
"github.com/spf13/cobra"
)
var subCommandFuncs = []func() *cobra.Command{
createCmd,
listCmd,
detailsCmd,
deleteCmd,
}
var serviceCommands = []func(cmd *cobra.Command) *cobra.Command{
addExchangeCommands,
addOneDriveCommands,
addSharePointCommands,
}
// AddCommands attaches all `corso backup * *` commands to the parent.
func AddCommands(cmd *cobra.Command) {
backupC := backupCmd()
cmd.AddCommand(backupC)
for _, sc := range subCommandFuncs {
subCommand := sc()
backupC.AddCommand(subCommand)
for _, addBackupTo := range serviceCommands {
addBackupTo(subCommand)
}
}
}
// The backup category of commands.
// `corso backup [<subcommand>] [<flag>...]`
func backupCmd() *cobra.Command {
return &cobra.Command{
Use: "backup",
Short: "Backup your service data",
Long: `Backup the data stored in one of your M365 services.`,
RunE: 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) error {
return cmd.Help()
}
// The backup create subcommand.
// `corso backup create <service> [<flag>...]`
var createCommand = "create"
func createCmd() *cobra.Command {
return &cobra.Command{
Use: createCommand,
Short: "Backup an M365 Service",
RunE: handleCreateCmd,
Args: cobra.NoArgs,
}
}
// Handler for calls to `corso backup create`.
// Produces the same output as `corso backup create --help`.
func handleCreateCmd(cmd *cobra.Command, args []string) error {
return cmd.Help()
}
// The backup list subcommand.
// `corso backup list <service> [<flag>...]`
var listCommand = "list"
func listCmd() *cobra.Command {
return &cobra.Command{
Use: listCommand,
Short: "List the history of backups for a service",
RunE: handleListCmd,
Args: cobra.NoArgs,
}
}
// Handler for calls to `corso backup list`.
// Produces the same output as `corso backup list --help`.
func handleListCmd(cmd *cobra.Command, args []string) error {
return cmd.Help()
}
// The backup details subcommand.
// `corso backup details <service> [<flag>...]`
var detailsCommand = "details"
func detailsCmd() *cobra.Command {
return &cobra.Command{
Use: detailsCommand,
Short: "Shows the details of a backup for a service",
RunE: handleDetailsCmd,
Args: cobra.NoArgs,
}
}
// Handler for calls to `corso backup details`.
// Produces the same output as `corso backup details --help`.
func handleDetailsCmd(cmd *cobra.Command, args []string) error {
return cmd.Help()
}
// The backup delete subcommand.
// `corso backup delete <service> [<flag>...]`
var deleteCommand = "delete"
func deleteCmd() *cobra.Command {
return &cobra.Command{
Use: deleteCommand,
Short: "Deletes a backup for a service",
RunE: handleDeleteCmd,
Args: cobra.NoArgs,
}
}
// Handler for calls to `corso backup delete`.
// Produces the same output as `corso backup delete --help`.
func handleDeleteCmd(cmd *cobra.Command, args []string) error {
return cmd.Help()
}