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()
opts := utils.OneDriveOpts{
Users: utils.User,
FileNames: utils.FileNames,
FolderPaths: utils.FolderPaths,
FileNames: utils.FileName,
FolderPaths: utils.FolderPath,
FileCreatedAfter: utils.FileCreatedAfter,
FileCreatedBefore: utils.FileCreatedBefore,
FileModifiedAfter: utils.FileModifiedAfter,

View File

@ -79,6 +79,7 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command {
c.Use = c.Use + " " + sharePointServiceCommandCreateUseSuffix
c.Example = sharePointServiceCommandCreateExamples
utils.AddSiteFlag(cmd)
utils.AddSiteIDFlag(cmd)
@ -144,7 +145,7 @@ func createSharePointCmd(cmd *cobra.Command, args []string) error {
return nil
}
if err := validateSharePointBackupCreateFlags(utils.Site, utils.WebURL, sharepointData); err != nil {
if err := validateSharePointBackupCreateFlags(utils.SiteID, utils.WebURL, sharepointData); err != nil {
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"))
}
sel, err := sharePointBackupCreateSelectors(ctx, utils.Site, utils.WebURL, sharepointData, gc)
sel, err := sharePointBackupCreateSelectors(ctx, utils.SiteID, utils.WebURL, sharepointData, gc)
if err != nil {
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()
opts := utils.SharePointOpts{
FolderPaths: utils.FolderPaths,
FileNames: utils.FileNames,
FolderPath: utils.FolderPath,
FileName: utils.FileName,
Library: utils.Library,
Sites: utils.Site,
WebURLs: utils.WebURL,
SiteID: utils.SiteID,
WebURL: utils.WebURL,
FileCreatedAfter: fileCreatedAfter,
FileCreatedBefore: fileCreatedBefore,
FileModifiedAfter: fileModifiedAfter,

View File

@ -15,16 +15,6 @@ import (
"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.
func addOneDriveCommands(cmd *cobra.Command) *cobra.Command {
var (
@ -92,8 +82,8 @@ func restoreOneDriveCmd(cmd *cobra.Command, args []string) error {
opts := utils.OneDriveOpts{
Users: user,
FileNames: fileNames,
FolderPaths: folderPaths,
FileNames: utils.FileName,
FolderPaths: utils.FolderPath,
FileCreatedAfter: utils.FileCreatedAfter,
FileCreatedBefore: utils.FileCreatedBefore,
FileModifiedAfter: utils.FileModifiedAfter,

View File

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

View File

@ -14,8 +14,8 @@ import (
var (
BackupID string
FolderPaths []string
FileNames []string
FolderPath []string
FileName []string
FileCreatedAfter string
FileCreatedBefore string
@ -23,7 +23,7 @@ var (
FileModifiedBefore string
Library string
Site []string
SiteID []string
WebURL []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
// work. Users must call --site-id a --site-id b --site-id c.
fs.StringArrayVar(
&Site,
&SiteID,
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.")

View File

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

View File

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

View File

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

View File

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