corso/src/cli/debug/sharepoint.go
Keepers 73b4ba3e0c
introduce debug commands (#4533)
adds the primary `debug` command to the cli as
a hidden command option.  Also includes the scaffold for
a `metadata-files` command that could be used to print
out the metadata files in the backup.

---

#### Does this PR need a docs update or release note?

- [x]  No

#### Type of change

- [x] 🌻 Feature

#### Test Plan

- [x]  Unit test
2023-10-30 17:13:48 +00:00

72 lines
1.9 KiB
Go

package debug
import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/alcionai/corso/src/cli/flags"
"github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/pkg/selectors"
)
// called by debug.go to map subcommands to provider-specific handling.
func addSharePointCommands(cmd *cobra.Command) *cobra.Command {
var (
c *cobra.Command
fs *pflag.FlagSet
)
switch cmd.Use {
case metadataFilesCommand:
c, fs = utils.AddCommand(cmd, sharePointMetadataFilesCmd(), utils.MarkDebugCommand())
c.Use = c.Use + " " + sharePointServiceCommandUseSuffix
// Flags addition ordering should follow the order we want them to appear in help and docs:
// More generic (ex: --user) and more frequently used flags take precedence.
fs.SortFlags = false
flags.AddBackupIDFlag(c, true)
}
return c
}
const (
sharePointServiceCommand = "sharepoint"
sharePointServiceCommandUseSuffix = "--backup <backupId>"
//nolint:lll
sharePointServiceCommandDebugExamples = `# Display file contents for backup 1234abcd
corso debug metadata-files sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd`
)
// `corso debug metadata-files sharepoint [<flag>...] <destination>`
func sharePointMetadataFilesCmd() *cobra.Command {
return &cobra.Command{
Use: sharePointServiceCommand,
Short: "Display sharepoint metadata file content",
RunE: metadataFilesSharePointCmd,
Args: cobra.NoArgs,
Example: sharePointServiceCommandDebugExamples,
}
}
func metadataFilesSharePointCmd(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
if utils.HasNoFlagsAndShownHelp(cmd) {
return nil
}
// opts := utils.MakeSharePointOpts(cmd)
if flags.RunModeFV == flags.RunModeFlagTest {
return nil
}
sel := selectors.NewSharePointBackup([]string{"unused-placeholder"})
return runMetadataFiles(ctx, cmd, args, sel.Selector, flags.BackupIDFV, "SharePoint")
}