--web-url to --site (#2838)

Changes ---web-url to --site, and changes --site
to --site-id.  Site-id is hidden to prevent confusion for end users.
This commit is contained in:
Keepers 2023-03-17 14:14:48 -06:00 committed by ryanfkeepers
parent a54f8a02f4
commit 61c64d610e
2 changed files with 35 additions and 19 deletions

View File

@ -35,20 +35,20 @@ const (
const ( const (
sharePointServiceCommand = "sharepoint" sharePointServiceCommand = "sharepoint"
sharePointServiceCommandCreateUseSuffix = "--web-url <siteURL> | '" + utils.Wildcard + "'" sharePointServiceCommandCreateUseSuffix = "--site <siteURL> | '" + utils.Wildcard + "'"
sharePointServiceCommandDeleteUseSuffix = "--backup <backupId>" sharePointServiceCommandDeleteUseSuffix = "--backup <backupId>"
sharePointServiceCommandDetailsUseSuffix = "--backup <backupId>" sharePointServiceCommandDetailsUseSuffix = "--backup <backupId>"
) )
const ( const (
sharePointServiceCommandCreateExamples = `# Backup SharePoint data for a Site sharePointServiceCommandCreateExamples = `# Backup SharePoint data for a Site
corso backup create sharepoint --web-url <siteURL> corso backup create sharepoint --site <siteURL>
# Backup SharePoint for two sites: HR and Team # Backup SharePoint for two sites: HR and Team
corso backup create sharepoint --web-url https://example.com/hr,https://example.com/team corso backup create sharepoint --site https://example.com/hr,https://example.com/team
# Backup all SharePoint data for all Sites # Backup all SharePoint data for all Sites
corso backup create sharepoint --web-url '*'` corso backup create sharepoint --site '*'`
sharePointServiceCommandDeleteExamples = `# Delete SharePoint backup with ID 1234abcd-12ab-cd34-56de-1234abcd sharePointServiceCommandDeleteExamples = `# Delete SharePoint backup with ID 1234abcd-12ab-cd34-56de-1234abcd
corso backup delete sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd` corso backup delete sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd`
@ -79,16 +79,8 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command {
c.Use = c.Use + " " + sharePointServiceCommandCreateUseSuffix c.Use = c.Use + " " + sharePointServiceCommandCreateUseSuffix
c.Example = sharePointServiceCommandCreateExamples c.Example = sharePointServiceCommandCreateExamples
utils.AddSiteFlag(cmd)
fs.StringArrayVar( utils.AddSiteIDFlag(cmd)
&utils.Site,
utils.SiteFN, nil,
"Backup SharePoint data by site ID; accepts '"+utils.Wildcard+"' to select all sites.")
fs.StringSliceVar(
&utils.WebURL,
utils.WebURLFN, nil,
"Restore data by site web URL; accepts '"+utils.Wildcard+"' to select all sites.")
fs.StringSliceVar( fs.StringSliceVar(
&sharepointData, &sharepointData,
@ -173,7 +165,7 @@ func createSharePointCmd(cmd *cobra.Command, args []string) error {
sel, err := sharePointBackupCreateSelectors(ctx, utils.Site, utils.WebURL, sharepointData, gc) sel, err := sharePointBackupCreateSelectors(ctx, utils.Site, utils.WebURL, sharepointData, gc)
if err != nil { if err != nil {
return Only(ctx, errors.Wrap(err, "Retrieving up sharepoint sites by ID and Web URL")) return Only(ctx, errors.Wrap(err, "Retrieving up sharepoint sites by ID and URL"))
} }
selectorSet := []selectors.Selector{} selectorSet := []selectors.Selector{}
@ -194,8 +186,7 @@ func validateSharePointBackupCreateFlags(sites, weburls, cats []string) error {
if len(sites) == 0 && len(weburls) == 0 { if len(sites) == 0 && len(weburls) == 0 {
return errors.New( return errors.New(
"requires one or more --" + "requires one or more --" +
utils.SiteFN + " ids, --" + utils.SiteFN + " urls, or the wildcard --" +
utils.WebURLFN + " urls, or the wildcard --" +
utils.SiteFN + " *", utils.SiteFN + " *",
) )
} }

View File

@ -34,9 +34,9 @@ const (
BackupFN = "backup" BackupFN = "backup"
DataFN = "data" DataFN = "data"
LibraryFN = "library" LibraryFN = "library"
SiteFN = "site" SiteFN = "site" // site only accepts WebURL values
SiteIDFN = "site-id" // site-id accepts actual site ids
UserFN = "user" UserFN = "user"
WebURLFN = "web-url"
FileFN = "file" FileFN = "file"
FolderFN = "folder" FolderFN = "folder"
@ -65,6 +65,31 @@ func AddUserFlag(cmd *cobra.Command) {
cobra.CheckErr(cmd.MarkFlagRequired(UserFN)) cobra.CheckErr(cmd.MarkFlagRequired(UserFN))
} }
// AddSiteIDFlag adds the --site-id flag, which accepts site ID values.
// This flag is hidden, since we expect users to prefer the --site url
// and do not want to encourage confusion.
func AddSiteIDFlag(cmd *cobra.Command) {
fs := cmd.Flags()
// note string ARRAY var. IDs naturally contain commas, so we cannot accept
// duplicate values within a flag declaration. ie: --site-id a,b,c does not
// work. Users must call --site-id a --site-id b --site-id c.
fs.StringArrayVar(
&Site,
SiteIDFN, nil,
//nolint:lll
"Backup data by site ID; accepts '"+Wildcard+"' to select all sites. Args cannot be comma-delimited and must use multiple flags.")
cobra.CheckErr(fs.MarkHidden(SiteIDFN))
}
// AddSiteFlag adds the --site flag, which accepts webURL values.
func AddSiteFlag(cmd *cobra.Command) {
cmd.Flags().StringSliceVar(
&WebURL,
SiteFN, nil,
"Backup data by site URL; accepts '"+Wildcard+"' to select all sites.")
}
type PopulatedFlags map[string]struct{} type PopulatedFlags map[string]struct{}
func (fs PopulatedFlags) populate(pf *pflag.Flag) { func (fs PopulatedFlags) populate(pf *pflag.Flag) {