diff --git a/src/cli/restore/sharepoint.go b/src/cli/restore/sharepoint.go index c9e6e2bcc..fadd36a48 100644 --- a/src/cli/restore/sharepoint.go +++ b/src/cli/restore/sharepoint.go @@ -16,6 +16,8 @@ import ( ) var ( + listItems []string + listPaths []string libraryItems []string libraryPaths []string site []string @@ -55,7 +57,7 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command { // sharepoint hierarchy (path/name) flags fs.StringSliceVar( - &folderPaths, + &libraryPaths, utils.LibraryFN, nil, "Restore library items by SharePoint library") @@ -64,6 +66,16 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command { utils.LibraryItemFN, nil, "Restore library items by file name or ID") + fs.StringSliceVar( + &listPaths, + utils.ListFN, nil, + "Restore list items by SharePoint list ID") + + fs.StringSliceVar( + &listItems, + utils.ListItemFN, nil, + "Restore list items by ID") + // sharepoint info flags // fs.StringVar( @@ -115,6 +127,8 @@ func restoreSharePointCmd(cmd *cobra.Command, args []string) error { } opts := utils.SharePointOpts{ + ListItems: listItems, + ListPaths: listPaths, LibraryItems: libraryItems, LibraryPaths: libraryPaths, Sites: site, diff --git a/src/cli/utils/sharepoint.go b/src/cli/utils/sharepoint.go index c3fdd69a7..f5e3d602f 100644 --- a/src/cli/utils/sharepoint.go +++ b/src/cli/utils/sharepoint.go @@ -9,12 +9,16 @@ import ( const ( LibraryItemFN = "library-item" LibraryFN = "library" + ListItemFN = "list-item" + ListFN = "list" WebURLFN = "web-url" ) type SharePointOpts struct { LibraryItems []string LibraryPaths []string + ListItems []string + ListPaths []string Sites []string WebURLs []string @@ -56,12 +60,13 @@ func IncludeSharePointRestoreDataSelectors( ) { lp, li := len(opts.LibraryPaths), len(opts.LibraryItems) ls, lwu := len(opts.Sites), len(opts.WebURLs) + slp, sli := len(opts.ListPaths), len(opts.ListItems) if ls == 0 { opts.Sites = selectors.Any() } - if lp+li+lwu == 0 { + if lp+li+lwu+slp+sli == 0 { sel.Include(sel.Sites(opts.Sites)) return @@ -84,6 +89,23 @@ func IncludeSharePointRestoreDataSelectors( } } + if slp+sli > 0 { + if sli == 0 { + opts.ListItems = selectors.Any() + } + + opts.ListPaths = trimFolderSlash(opts.ListPaths) + containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.ListPaths) + + if len(containsFolders) > 0 { + sel.Include(sel.ListItems(opts.Sites, containsFolders, opts.ListItems)) + } + + if len(prefixFolders) > 0 { + sel.Include(sel.ListItems(opts.Sites, prefixFolders, opts.ListItems, selectors.PrefixMatch())) + } + } + if lwu > 0 { opts.WebURLs = trimFolderSlash(opts.WebURLs) containsURLs, suffixURLs := splitFoldersIntoContainsAndPrefix(opts.WebURLs) diff --git a/src/cli/utils/sharepoint_test.go b/src/cli/utils/sharepoint_test.go index 3367d4a28..95ef19e89 100644 --- a/src/cli/utils/sharepoint_test.go +++ b/src/cli/utils/sharepoint_test.go @@ -53,6 +53,18 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() { }, expectIncludeLen: 3, }, + { + name: "single extended", + opts: utils.SharePointOpts{ + LibraryItems: single, + LibraryPaths: single, + ListItems: single, + ListPaths: single, + Sites: single, + WebURLs: single, + }, + expectIncludeLen: 4, + }, { name: "multi inputs", opts: utils.SharePointOpts{ @@ -93,6 +105,32 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() { }, expectIncludeLen: 2, }, + { + name: "list contains", + opts: utils.SharePointOpts{ + LibraryItems: empty, + LibraryPaths: empty, + ListItems: empty, + ListPaths: containsOnly, + Sites: empty, + WebURLs: empty, + }, + expectIncludeLen: 1, + }, + { + name: "list prefixes", + opts: utils.SharePointOpts{ + ListPaths: prefixOnly, + }, + expectIncludeLen: 1, + }, + { + name: "list prefixes and contains", + opts: utils.SharePointOpts{ + ListPaths: containsAndPrefix, + }, + expectIncludeLen: 2, + }, { name: "weburl contains", opts: utils.SharePointOpts{