--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 (
sharePointServiceCommand = "sharepoint"
sharePointServiceCommandCreateUseSuffix = "--web-url <siteURL> | '" + utils.Wildcard + "'"
sharePointServiceCommandCreateUseSuffix = "--site <siteURL> | '" + utils.Wildcard + "'"
sharePointServiceCommandDeleteUseSuffix = "--backup <backupId>"
sharePointServiceCommandDetailsUseSuffix = "--backup <backupId>"
)
const (
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
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
corso backup create sharepoint --web-url '*'`
corso backup create sharepoint --site '*'`
sharePointServiceCommandDeleteExamples = `# Delete SharePoint backup with ID 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.Example = sharePointServiceCommandCreateExamples
fs.StringArrayVar(
&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.")
utils.AddSiteFlag(cmd)
utils.AddSiteIDFlag(cmd)
fs.StringSliceVar(
&sharepointData,
@ -173,7 +165,7 @@ func createSharePointCmd(cmd *cobra.Command, args []string) error {
sel, err := sharePointBackupCreateSelectors(ctx, utils.Site, utils.WebURL, sharepointData, gc)
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{}
@ -194,8 +186,7 @@ func validateSharePointBackupCreateFlags(sites, weburls, cats []string) error {
if len(sites) == 0 && len(weburls) == 0 {
return errors.New(
"requires one or more --" +
utils.SiteFN + " ids, --" +
utils.WebURLFN + " urls, or the wildcard --" +
utils.SiteFN + " urls, or the wildcard --" +
utils.SiteFN + " *",
)
}

View File

@ -34,9 +34,9 @@ const (
BackupFN = "backup"
DataFN = "data"
LibraryFN = "library"
SiteFN = "site"
SiteFN = "site" // site only accepts WebURL values
SiteIDFN = "site-id" // site-id accepts actual site ids
UserFN = "user"
WebURLFN = "web-url"
FileFN = "file"
FolderFN = "folder"
@ -65,6 +65,31 @@ func AddUserFlag(cmd *cobra.Command) {
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{}
func (fs PopulatedFlags) populate(pf *pflag.Flag) {