Sharepoint List CLI commands added to package (#1972)
## Description CLI commands were added to facilitate restore of `SharePoint.Lists` to M365 <!-- Insert PR description--> ## Does this PR need a docs update or release note? - [x] 🕐 Yes, but in a later PR ## Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature ## Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * related to #1963<issue> ## Test Plan - [x] ⚡ Unit test
This commit is contained in:
parent
20ec708ea3
commit
b36ad340f2
@ -16,6 +16,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
listItems []string
|
||||||
|
listPaths []string
|
||||||
libraryItems []string
|
libraryItems []string
|
||||||
libraryPaths []string
|
libraryPaths []string
|
||||||
site []string
|
site []string
|
||||||
@ -55,7 +57,7 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command {
|
|||||||
// sharepoint hierarchy (path/name) flags
|
// sharepoint hierarchy (path/name) flags
|
||||||
|
|
||||||
fs.StringSliceVar(
|
fs.StringSliceVar(
|
||||||
&folderPaths,
|
&libraryPaths,
|
||||||
utils.LibraryFN, nil,
|
utils.LibraryFN, nil,
|
||||||
"Restore library items by SharePoint library")
|
"Restore library items by SharePoint library")
|
||||||
|
|
||||||
@ -64,6 +66,16 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command {
|
|||||||
utils.LibraryItemFN, nil,
|
utils.LibraryItemFN, nil,
|
||||||
"Restore library items by file name or ID")
|
"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
|
// sharepoint info flags
|
||||||
|
|
||||||
// fs.StringVar(
|
// fs.StringVar(
|
||||||
@ -115,6 +127,8 @@ func restoreSharePointCmd(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
opts := utils.SharePointOpts{
|
opts := utils.SharePointOpts{
|
||||||
|
ListItems: listItems,
|
||||||
|
ListPaths: listPaths,
|
||||||
LibraryItems: libraryItems,
|
LibraryItems: libraryItems,
|
||||||
LibraryPaths: libraryPaths,
|
LibraryPaths: libraryPaths,
|
||||||
Sites: site,
|
Sites: site,
|
||||||
|
|||||||
@ -9,12 +9,16 @@ import (
|
|||||||
const (
|
const (
|
||||||
LibraryItemFN = "library-item"
|
LibraryItemFN = "library-item"
|
||||||
LibraryFN = "library"
|
LibraryFN = "library"
|
||||||
|
ListItemFN = "list-item"
|
||||||
|
ListFN = "list"
|
||||||
WebURLFN = "web-url"
|
WebURLFN = "web-url"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SharePointOpts struct {
|
type SharePointOpts struct {
|
||||||
LibraryItems []string
|
LibraryItems []string
|
||||||
LibraryPaths []string
|
LibraryPaths []string
|
||||||
|
ListItems []string
|
||||||
|
ListPaths []string
|
||||||
Sites []string
|
Sites []string
|
||||||
WebURLs []string
|
WebURLs []string
|
||||||
|
|
||||||
@ -56,12 +60,13 @@ func IncludeSharePointRestoreDataSelectors(
|
|||||||
) {
|
) {
|
||||||
lp, li := len(opts.LibraryPaths), len(opts.LibraryItems)
|
lp, li := len(opts.LibraryPaths), len(opts.LibraryItems)
|
||||||
ls, lwu := len(opts.Sites), len(opts.WebURLs)
|
ls, lwu := len(opts.Sites), len(opts.WebURLs)
|
||||||
|
slp, sli := len(opts.ListPaths), len(opts.ListItems)
|
||||||
|
|
||||||
if ls == 0 {
|
if ls == 0 {
|
||||||
opts.Sites = selectors.Any()
|
opts.Sites = selectors.Any()
|
||||||
}
|
}
|
||||||
|
|
||||||
if lp+li+lwu == 0 {
|
if lp+li+lwu+slp+sli == 0 {
|
||||||
sel.Include(sel.Sites(opts.Sites))
|
sel.Include(sel.Sites(opts.Sites))
|
||||||
|
|
||||||
return
|
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 {
|
if lwu > 0 {
|
||||||
opts.WebURLs = trimFolderSlash(opts.WebURLs)
|
opts.WebURLs = trimFolderSlash(opts.WebURLs)
|
||||||
containsURLs, suffixURLs := splitFoldersIntoContainsAndPrefix(opts.WebURLs)
|
containsURLs, suffixURLs := splitFoldersIntoContainsAndPrefix(opts.WebURLs)
|
||||||
|
|||||||
@ -53,6 +53,18 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
|
|||||||
},
|
},
|
||||||
expectIncludeLen: 3,
|
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",
|
name: "multi inputs",
|
||||||
opts: utils.SharePointOpts{
|
opts: utils.SharePointOpts{
|
||||||
@ -93,6 +105,32 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
|
|||||||
},
|
},
|
||||||
expectIncludeLen: 2,
|
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",
|
name: "weburl contains",
|
||||||
opts: utils.SharePointOpts{
|
opts: utils.SharePointOpts{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user