make all sharepoint flags singular (#2839)

This commit is contained in:
Keepers 2023-03-17 14:15:37 -06:00 committed by ryanfkeepers
parent 61c64d610e
commit b668fbec4c
9 changed files with 122 additions and 131 deletions

View File

@ -221,8 +221,8 @@ func detailsOneDriveCmd(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
opts := utils.OneDriveOpts{ opts := utils.OneDriveOpts{
Users: utils.User, Users: utils.User,
FileNames: utils.FileNames, FileNames: utils.FileName,
FolderPaths: utils.FolderPaths, FolderPaths: utils.FolderPath,
FileCreatedAfter: utils.FileCreatedAfter, FileCreatedAfter: utils.FileCreatedAfter,
FileCreatedBefore: utils.FileCreatedBefore, FileCreatedBefore: utils.FileCreatedBefore,
FileModifiedAfter: utils.FileModifiedAfter, FileModifiedAfter: utils.FileModifiedAfter,

View File

@ -79,6 +79,7 @@ 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) utils.AddSiteFlag(cmd)
utils.AddSiteIDFlag(cmd) utils.AddSiteIDFlag(cmd)
@ -144,7 +145,7 @@ func createSharePointCmd(cmd *cobra.Command, args []string) error {
return nil return nil
} }
if err := validateSharePointBackupCreateFlags(utils.Site, utils.WebURL, sharepointData); err != nil { if err := validateSharePointBackupCreateFlags(utils.SiteID, utils.WebURL, sharepointData); err != nil {
return err return err
} }
@ -163,7 +164,7 @@ func createSharePointCmd(cmd *cobra.Command, args []string) error {
return Only(ctx, errors.Wrap(err, "Failed to connect to Microsoft APIs")) return Only(ctx, errors.Wrap(err, "Failed to connect to Microsoft APIs"))
} }
sel, err := sharePointBackupCreateSelectors(ctx, utils.Site, utils.WebURL, sharepointData, gc) sel, err := sharePointBackupCreateSelectors(ctx, utils.SiteID, utils.WebURL, sharepointData, gc)
if err != nil { if err != nil {
return Only(ctx, errors.Wrap(err, "Retrieving up sharepoint sites by ID and URL")) return Only(ctx, errors.Wrap(err, "Retrieving up sharepoint sites by ID and URL"))
} }
@ -325,11 +326,11 @@ func detailsSharePointCmd(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
opts := utils.SharePointOpts{ opts := utils.SharePointOpts{
FolderPaths: utils.FolderPaths, FolderPath: utils.FolderPath,
FileNames: utils.FileNames, FileName: utils.FileName,
Library: utils.Library, Library: utils.Library,
Sites: utils.Site, SiteID: utils.SiteID,
WebURLs: utils.WebURL, WebURL: utils.WebURL,
FileCreatedAfter: fileCreatedAfter, FileCreatedAfter: fileCreatedAfter,
FileCreatedBefore: fileCreatedBefore, FileCreatedBefore: fileCreatedBefore,
FileModifiedAfter: fileModifiedAfter, FileModifiedAfter: fileModifiedAfter,

View File

@ -15,16 +15,6 @@ import (
"github.com/alcionai/corso/src/pkg/repository" "github.com/alcionai/corso/src/pkg/repository"
) )
var (
folderPaths []string
fileNames []string
fileCreatedAfter string
fileCreatedBefore string
fileModifiedAfter string
fileModifiedBefore string
)
// called by restore.go to map subcommands to provider-specific handling. // called by restore.go to map subcommands to provider-specific handling.
func addOneDriveCommands(cmd *cobra.Command) *cobra.Command { func addOneDriveCommands(cmd *cobra.Command) *cobra.Command {
var ( var (
@ -92,8 +82,8 @@ func restoreOneDriveCmd(cmd *cobra.Command, args []string) error {
opts := utils.OneDriveOpts{ opts := utils.OneDriveOpts{
Users: user, Users: user,
FileNames: fileNames, FileNames: utils.FileName,
FolderPaths: folderPaths, FolderPaths: utils.FolderPath,
FileCreatedAfter: utils.FileCreatedAfter, FileCreatedAfter: utils.FileCreatedAfter,
FileCreatedBefore: utils.FileCreatedBefore, FileCreatedBefore: utils.FileCreatedBefore,
FileModifiedAfter: utils.FileModifiedAfter, FileModifiedAfter: utils.FileModifiedAfter,

View File

@ -90,15 +90,15 @@ func restoreSharePointCmd(cmd *cobra.Command, args []string) error {
} }
opts := utils.SharePointOpts{ opts := utils.SharePointOpts{
FileNames: utils.FileNames, FileName: utils.FileName,
FolderPaths: utils.FolderPaths, FolderPath: utils.FolderPath,
Library: utils.Library, Library: utils.Library,
ListItems: listItems, ListItem: listItems,
ListPaths: listPaths, ListPath: listPaths,
PageFolders: pageFolders, PageFolder: pageFolders,
Pages: pages, Page: pages,
Sites: utils.Site, SiteID: utils.SiteID,
WebURLs: utils.WebURL, WebURL: utils.WebURL,
FileCreatedAfter: utils.FileCreatedAfter, FileCreatedAfter: utils.FileCreatedAfter,
FileCreatedBefore: utils.FileCreatedBefore, FileCreatedBefore: utils.FileCreatedBefore,
FileModifiedAfter: utils.FileModifiedAfter, FileModifiedAfter: utils.FileModifiedAfter,

View File

@ -14,8 +14,8 @@ import (
var ( var (
BackupID string BackupID string
FolderPaths []string FolderPath []string
FileNames []string FileName []string
FileCreatedAfter string FileCreatedAfter string
FileCreatedBefore string FileCreatedBefore string
@ -23,7 +23,7 @@ var (
FileModifiedBefore string FileModifiedBefore string
Library string Library string
Site []string SiteID []string
WebURL []string WebURL []string
User []string User []string
@ -75,7 +75,7 @@ func AddSiteIDFlag(cmd *cobra.Command) {
// duplicate values within a flag declaration. ie: --site-id a,b,c does not // 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. // work. Users must call --site-id a --site-id b --site-id c.
fs.StringArrayVar( fs.StringArrayVar(
&Site, &SiteID,
SiteIDFN, nil, SiteIDFN, nil,
//nolint:lll //nolint:lll
"Backup data by site ID; accepts '"+Wildcard+"' to select all sites. Args cannot be comma-delimited and must use multiple flags.") "Backup data by site ID; accepts '"+Wildcard+"' to select all sites. Args cannot be comma-delimited and must use multiple flags.")

View File

@ -25,12 +25,12 @@ func AddOneDriveDetailsAndRestoreFlags(cmd *cobra.Command) {
fs := cmd.Flags() fs := cmd.Flags()
fs.StringSliceVar( fs.StringSliceVar(
&FolderPaths, &FolderPath,
FolderFN, nil, FolderFN, nil,
"Select files by OneDrive folder; defaults to root.") "Select files by OneDrive folder; defaults to root.")
fs.StringSliceVar( fs.StringSliceVar(
&FileNames, &FileName,
FileFN, nil, FileFN, nil,
"Select files by name.") "Select files by name.")

View File

@ -10,29 +10,29 @@ import (
const ( const (
ListItemFN = "list-item" ListItemFN = "list-item"
ListFN = "list" ListFN = "list"
PageFolderFN = "page-folders" PageFolderFN = "page-folder"
PagesFN = "pages" PagesFN = "page"
) )
// flag population variables // flag population variables
var ( var (
PageFolders []string PageFolder []string
Pages []string Page []string
) )
type SharePointOpts struct { type SharePointOpts struct {
Library string Library string
FileNames []string // for libraries, to duplicate onedrive interface FileName []string // for libraries, to duplicate onedrive interface
FolderPaths []string // for libraries, to duplicate onedrive interface FolderPath []string // for libraries, to duplicate onedrive interface
ListItems []string ListItem []string
ListPaths []string ListPath []string
PageFolders []string PageFolder []string
Pages []string Page []string
Sites []string SiteID []string
WebURLs []string WebURL []string
FileCreatedAfter string FileCreatedAfter string
FileCreatedBefore string FileCreatedBefore string
@ -53,23 +53,23 @@ func AddSharePointDetailsAndRestoreFlags(cmd *cobra.Command) {
"Select only this library. Default includes all libraries.") "Select only this library. Default includes all libraries.")
fs.StringSliceVar( fs.StringSliceVar(
&FolderPaths, &FolderPath,
FolderFN, nil, FolderFN, nil,
"Select by folder; defaults to root.") "Select by folder; defaults to root.")
fs.StringSliceVar( fs.StringSliceVar(
&FileNames, &FileName,
FileFN, nil, FileFN, nil,
"Select by file name.") "Select by file name.")
fs.StringSliceVar( fs.StringSliceVar(
&PageFolders, &PageFolder,
PageFolderFN, nil, PageFolderFN, nil,
"Select pages by folder name; accepts '"+Wildcard+"' to select all folders.") "Select pages by folder name; accepts '"+Wildcard+"' to select all folders.")
cobra.CheckErr(fs.MarkHidden(PageFolderFN)) cobra.CheckErr(fs.MarkHidden(PageFolderFN))
fs.StringSliceVar( fs.StringSliceVar(
&Pages, &Page,
PagesFN, nil, PagesFN, nil,
"Select pages by item name; accepts '"+Wildcard+"' to select all pages within the site.") "Select pages by item name; accepts '"+Wildcard+"' to select all pages within the site.")
cobra.CheckErr(fs.MarkHidden(PagesFN)) cobra.CheckErr(fs.MarkHidden(PagesFN))
@ -136,12 +136,12 @@ func AddSharePointFilter(
// IncludeSharePointRestoreDataSelectors builds the common data-selector // IncludeSharePointRestoreDataSelectors builds the common data-selector
// inclusions for SharePoint commands. // inclusions for SharePoint commands.
func IncludeSharePointRestoreDataSelectors(opts SharePointOpts) *selectors.SharePointRestore { func IncludeSharePointRestoreDataSelectors(opts SharePointOpts) *selectors.SharePointRestore {
sites := opts.Sites sites := opts.SiteID
lfp, lfn := len(opts.FolderPaths), len(opts.FileNames) lfp, lfn := len(opts.FolderPath), len(opts.FileName)
ls, lwu := len(opts.Sites), len(opts.WebURLs) ls, lwu := len(opts.SiteID), len(opts.WebURL)
slp, sli := len(opts.ListPaths), len(opts.ListItems) slp, sli := len(opts.ListPath), len(opts.ListItem)
pf, pi := len(opts.PageFolders), len(opts.Pages) pf, pi := len(opts.PageFolder), len(opts.Page)
if ls == 0 { if ls == 0 {
sites = selectors.Any() sites = selectors.Any()
@ -156,58 +156,58 @@ func IncludeSharePointRestoreDataSelectors(opts SharePointOpts) *selectors.Share
if lfp+lfn > 0 { if lfp+lfn > 0 {
if lfn == 0 { if lfn == 0 {
opts.FileNames = selectors.Any() opts.FileName = selectors.Any()
} }
opts.FolderPaths = trimFolderSlash(opts.FolderPaths) opts.FolderPath = trimFolderSlash(opts.FolderPath)
containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.FolderPaths) containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.FolderPath)
if len(containsFolders) > 0 { if len(containsFolders) > 0 {
sel.Include(sel.LibraryItems(containsFolders, opts.FileNames)) sel.Include(sel.LibraryItems(containsFolders, opts.FileName))
} }
if len(prefixFolders) > 0 { if len(prefixFolders) > 0 {
sel.Include(sel.LibraryItems(prefixFolders, opts.FileNames, selectors.PrefixMatch())) sel.Include(sel.LibraryItems(prefixFolders, opts.FileName, selectors.PrefixMatch()))
} }
} }
if slp+sli > 0 { if slp+sli > 0 {
if sli == 0 { if sli == 0 {
opts.ListItems = selectors.Any() opts.ListItem = selectors.Any()
} }
opts.ListPaths = trimFolderSlash(opts.ListPaths) opts.ListPath = trimFolderSlash(opts.ListPath)
containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.ListPaths) containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.ListPath)
if len(containsFolders) > 0 { if len(containsFolders) > 0 {
sel.Include(sel.ListItems(containsFolders, opts.ListItems)) sel.Include(sel.ListItems(containsFolders, opts.ListItem))
} }
if len(prefixFolders) > 0 { if len(prefixFolders) > 0 {
sel.Include(sel.ListItems(prefixFolders, opts.ListItems, selectors.PrefixMatch())) sel.Include(sel.ListItems(prefixFolders, opts.ListItem, selectors.PrefixMatch()))
} }
} }
if pf+pi > 0 { if pf+pi > 0 {
if pi == 0 { if pi == 0 {
opts.Pages = selectors.Any() opts.Page = selectors.Any()
} }
opts.PageFolders = trimFolderSlash(opts.PageFolders) opts.PageFolder = trimFolderSlash(opts.PageFolder)
containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.PageFolders) containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.PageFolder)
if len(containsFolders) > 0 { if len(containsFolders) > 0 {
sel.Include(sel.PageItems(containsFolders, opts.Pages)) sel.Include(sel.PageItems(containsFolders, opts.Page))
} }
if len(prefixFolders) > 0 { if len(prefixFolders) > 0 {
sel.Include(sel.PageItems(prefixFolders, opts.Pages, selectors.PrefixMatch())) sel.Include(sel.PageItems(prefixFolders, opts.Page, selectors.PrefixMatch()))
} }
} }
if lwu > 0 { if lwu > 0 {
opts.WebURLs = trimFolderSlash(opts.WebURLs) opts.WebURL = trimFolderSlash(opts.WebURL)
containsURLs, suffixURLs := splitFoldersIntoContainsAndPrefix(opts.WebURLs) containsURLs, suffixURLs := splitFoldersIntoContainsAndPrefix(opts.WebURL)
if len(containsURLs) > 0 { if len(containsURLs) > 0 {
sel.Include(sel.WebURL(containsURLs)) sel.Include(sel.WebURL(containsURLs))

View File

@ -43,140 +43,140 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
{ {
name: "single inputs", name: "single inputs",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
FileNames: single, FileName: single,
FolderPaths: single, FolderPath: single,
Sites: single, SiteID: single,
WebURLs: single, WebURL: single,
}, },
expectIncludeLen: 4, expectIncludeLen: 4,
}, },
{ {
name: "single extended", name: "single extended",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
FileNames: single, FileName: single,
FolderPaths: single, FolderPath: single,
ListItems: single, ListItem: single,
ListPaths: single, ListPath: single,
Sites: single, SiteID: single,
WebURLs: single, WebURL: single,
}, },
expectIncludeLen: 5, expectIncludeLen: 5,
}, },
{ {
name: "multi inputs", name: "multi inputs",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
FileNames: multi, FileName: multi,
FolderPaths: multi, FolderPath: multi,
Sites: multi, SiteID: multi,
WebURLs: multi, WebURL: multi,
}, },
expectIncludeLen: 4, expectIncludeLen: 4,
}, },
{ {
name: "library folder contains", name: "library folder contains",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
FileNames: empty, FileName: empty,
FolderPaths: containsOnly, FolderPath: containsOnly,
Sites: empty, SiteID: empty,
WebURLs: empty, WebURL: empty,
}, },
expectIncludeLen: 1, expectIncludeLen: 1,
}, },
{ {
name: "library folder prefixes", name: "library folder prefixes",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
FileNames: empty, FileName: empty,
FolderPaths: prefixOnly, FolderPath: prefixOnly,
Sites: empty, SiteID: empty,
WebURLs: empty, WebURL: empty,
}, },
expectIncludeLen: 1, expectIncludeLen: 1,
}, },
{ {
name: "library folder prefixes and contains", name: "library folder prefixes and contains",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
FileNames: empty, FileName: empty,
FolderPaths: containsAndPrefix, FolderPath: containsAndPrefix,
Sites: empty, SiteID: empty,
WebURLs: empty, WebURL: empty,
}, },
expectIncludeLen: 2, expectIncludeLen: 2,
}, },
{ {
name: "list contains", name: "list contains",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
FileNames: empty, FileName: empty,
FolderPaths: empty, FolderPath: empty,
ListItems: empty, ListItem: empty,
ListPaths: containsOnly, ListPath: containsOnly,
Sites: empty, SiteID: empty,
WebURLs: empty, WebURL: empty,
}, },
expectIncludeLen: 1, expectIncludeLen: 1,
}, },
{ {
name: "list prefixes", name: "list prefixes",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
ListPaths: prefixOnly, ListPath: prefixOnly,
}, },
expectIncludeLen: 1, expectIncludeLen: 1,
}, },
{ {
name: "list prefixes and contains", name: "list prefixes and contains",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
ListPaths: containsAndPrefix, ListPath: containsAndPrefix,
}, },
expectIncludeLen: 2, expectIncludeLen: 2,
}, },
{ {
name: "weburl contains", name: "weburl contains",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
FileNames: empty, FileName: empty,
FolderPaths: empty, FolderPath: empty,
Sites: empty, SiteID: empty,
WebURLs: containsOnly, WebURL: containsOnly,
}, },
expectIncludeLen: 3, expectIncludeLen: 3,
}, },
{ {
name: "library folder suffixes", name: "library folder suffixes",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
FileNames: empty, FileName: empty,
FolderPaths: empty, FolderPath: empty,
Sites: empty, SiteID: empty,
WebURLs: prefixOnly, // prefix pattern matches suffix pattern WebURL: prefixOnly, // prefix pattern matches suffix pattern
}, },
expectIncludeLen: 3, expectIncludeLen: 3,
}, },
{ {
name: "library folder suffixes and contains", name: "library folder suffixes and contains",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
FileNames: empty, FileName: empty,
FolderPaths: empty, FolderPath: empty,
Sites: empty, SiteID: empty,
WebURLs: containsAndPrefix, // prefix pattern matches suffix pattern WebURL: containsAndPrefix, // prefix pattern matches suffix pattern
}, },
expectIncludeLen: 6, expectIncludeLen: 6,
}, },
{ {
name: "Page Folder", name: "Page Folder",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
PageFolders: single, PageFolder: single,
}, },
expectIncludeLen: 1, expectIncludeLen: 1,
}, },
{ {
name: "Site Page ", name: "Site Page ",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
Pages: single, Page: single,
}, },
expectIncludeLen: 1, expectIncludeLen: 1,
}, },
{ {
name: "Page & library Files", name: "Page & library Files",
opts: utils.SharePointOpts{ opts: utils.SharePointOpts{
PageFolders: single, PageFolder: single,
FileNames: multi, FileName: multi,
}, },
expectIncludeLen: 2, expectIncludeLen: 2,
}, },

View File

@ -470,28 +470,28 @@ var (
Name: "AllLibraryItems", Name: "AllLibraryItems",
Expected: testdata.SharePointLibraryItems, Expected: testdata.SharePointLibraryItems,
Opts: utils.SharePointOpts{ Opts: utils.SharePointOpts{
FolderPaths: selectors.Any(), FolderPath: selectors.Any(),
}, },
}, },
{ {
Name: "FolderPrefixMatch", Name: "FolderPrefixMatch",
Expected: testdata.SharePointLibraryItems, Expected: testdata.SharePointLibraryItems,
Opts: utils.SharePointOpts{ Opts: utils.SharePointOpts{
FolderPaths: []string{testdata.SharePointLibraryFolder}, FolderPath: []string{testdata.SharePointLibraryFolder},
}, },
}, },
{ {
Name: "FolderPrefixMatchTrailingSlash", Name: "FolderPrefixMatchTrailingSlash",
Expected: testdata.SharePointLibraryItems, Expected: testdata.SharePointLibraryItems,
Opts: utils.SharePointOpts{ Opts: utils.SharePointOpts{
FolderPaths: []string{testdata.SharePointLibraryFolder + "/"}, FolderPath: []string{testdata.SharePointLibraryFolder + "/"},
}, },
}, },
{ {
Name: "FolderPrefixMatchTrailingSlash", Name: "FolderPrefixMatchTrailingSlash",
Expected: testdata.SharePointLibraryItems, Expected: testdata.SharePointLibraryItems,
Opts: utils.SharePointOpts{ Opts: utils.SharePointOpts{
FolderPaths: []string{testdata.SharePointLibraryFolder + "/"}, FolderPath: []string{testdata.SharePointLibraryFolder + "/"},
}, },
}, },
{ {
@ -501,7 +501,7 @@ var (
testdata.SharePointLibraryItems[1], testdata.SharePointLibraryItems[1],
}, },
Opts: utils.SharePointOpts{ Opts: utils.SharePointOpts{
FileNames: []string{ FileName: []string{
testdata.SharePointLibraryItems[0].ShortRef, testdata.SharePointLibraryItems[0].ShortRef,
testdata.SharePointLibraryItems[1].ShortRef, testdata.SharePointLibraryItems[1].ShortRef,
}, },
@ -511,7 +511,7 @@ var (
Name: "SingleItem", Name: "SingleItem",
Expected: []details.DetailsEntry{testdata.SharePointLibraryItems[0]}, Expected: []details.DetailsEntry{testdata.SharePointLibraryItems[0]},
Opts: utils.SharePointOpts{ Opts: utils.SharePointOpts{
FileNames: []string{ FileName: []string{
testdata.SharePointLibraryItems[0].SharePoint.ItemName, testdata.SharePointLibraryItems[0].SharePoint.ItemName,
}, },
}, },
@ -523,7 +523,7 @@ var (
testdata.SharePointLibraryItems[1], testdata.SharePointLibraryItems[1],
}, },
Opts: utils.SharePointOpts{ Opts: utils.SharePointOpts{
FileNames: []string{ FileName: []string{
testdata.SharePointLibraryItems[0].SharePoint.ItemName, testdata.SharePointLibraryItems[0].SharePoint.ItemName,
testdata.SharePointLibraryItems[1].SharePoint.ItemName, testdata.SharePointLibraryItems[1].SharePoint.ItemName,
}, },
@ -533,7 +533,7 @@ var (
Name: "NoSelectRepoItemName", Name: "NoSelectRepoItemName",
Expected: []details.DetailsEntry{}, Expected: []details.DetailsEntry{},
Opts: utils.SharePointOpts{ Opts: utils.SharePointOpts{
FileNames: []string{ FileName: []string{
testdata.SharePointLibraryItemPath1.Item(), testdata.SharePointLibraryItemPath1.Item(),
}, },
}, },