add sharepoint output columns, fix flag bugs (#1749)
## Description Extends the columns printed on sharePoint details to include the expected data. Fixes some bugs with flag processing for details and restore commands. ## Type of change - [x] 🌻 Feature - [x] 🐛 Bugfix ## Issue(s) * #1616 ## Test Plan - [x] 💪 Manual - [x] ⚡ Unit test
This commit is contained in:
parent
e2775aeb95
commit
a2330bc314
@ -54,30 +54,38 @@ func IncludeSharePointRestoreDataSelectors(
|
||||
sel *selectors.SharePointRestore,
|
||||
opts SharePointOpts,
|
||||
) {
|
||||
lp, ln, lwu := len(opts.LibraryPaths), len(opts.LibraryItems), len(opts.WebURLs)
|
||||
lp, li := len(opts.LibraryPaths), len(opts.LibraryItems)
|
||||
ls, lwu := len(opts.Sites), len(opts.WebURLs)
|
||||
|
||||
// only use the inclusion if either a path or item name
|
||||
// is specified
|
||||
if lp+ln == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if len(opts.Sites) == 0 {
|
||||
if ls == 0 {
|
||||
opts.Sites = selectors.Any()
|
||||
}
|
||||
|
||||
if lp+ln+lwu == 0 {
|
||||
if lp+li+lwu == 0 {
|
||||
sel.Include(sel.Sites(opts.Sites))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
opts.LibraryPaths = trimFolderSlash(opts.LibraryPaths)
|
||||
|
||||
if ln == 0 {
|
||||
if lp+li > 0 {
|
||||
if li == 0 {
|
||||
opts.LibraryItems = selectors.Any()
|
||||
}
|
||||
|
||||
opts.LibraryPaths = trimFolderSlash(opts.LibraryPaths)
|
||||
containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.LibraryPaths)
|
||||
|
||||
if len(containsFolders) > 0 {
|
||||
sel.Include(sel.LibraryItems(opts.Sites, containsFolders, opts.LibraryItems))
|
||||
}
|
||||
|
||||
if len(prefixFolders) > 0 {
|
||||
sel.Include(sel.LibraryItems(opts.Sites, prefixFolders, opts.LibraryItems, selectors.PrefixMatch()))
|
||||
}
|
||||
}
|
||||
|
||||
if lwu > 0 {
|
||||
opts.WebURLs = trimFolderSlash(opts.WebURLs)
|
||||
containsURLs, suffixURLs := splitFoldersIntoContainsAndPrefix(opts.WebURLs)
|
||||
|
||||
if len(containsURLs) > 0 {
|
||||
@ -87,15 +95,6 @@ func IncludeSharePointRestoreDataSelectors(
|
||||
if len(suffixURLs) > 0 {
|
||||
sel.Include(sel.WebURL(suffixURLs, selectors.SuffixMatch()))
|
||||
}
|
||||
|
||||
containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.LibraryPaths)
|
||||
|
||||
if len(containsFolders) > 0 {
|
||||
sel.Include(sel.LibraryItems(opts.Sites, containsFolders, opts.LibraryItems))
|
||||
}
|
||||
|
||||
if len(prefixFolders) > 0 {
|
||||
sel.Include(sel.LibraryItems(opts.Sites, prefixFolders, opts.LibraryItems, selectors.PrefixMatch()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -19,8 +19,6 @@ func TestSharePointUtilsSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
|
||||
suite.T().Skip("just until next PR")
|
||||
|
||||
var (
|
||||
empty = []string{}
|
||||
single = []string{"single"}
|
||||
@ -43,7 +41,7 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
|
||||
Sites: empty,
|
||||
WebURLs: empty,
|
||||
},
|
||||
expectIncludeLen: 0,
|
||||
expectIncludeLen: 1,
|
||||
},
|
||||
{
|
||||
name: "single inputs",
|
||||
@ -53,7 +51,7 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
|
||||
Sites: single,
|
||||
WebURLs: single,
|
||||
},
|
||||
expectIncludeLen: 1,
|
||||
expectIncludeLen: 2,
|
||||
},
|
||||
{
|
||||
name: "multi inputs",
|
||||
@ -63,7 +61,7 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
|
||||
Sites: multi,
|
||||
WebURLs: multi,
|
||||
},
|
||||
expectIncludeLen: 1,
|
||||
expectIncludeLen: 2,
|
||||
},
|
||||
{
|
||||
name: "library contains",
|
||||
|
||||
@ -355,7 +355,7 @@ type SharePointInfo struct {
|
||||
ItemType ItemType `json:"itemType,omitempty"`
|
||||
Modified time.Time `josn:"modified,omitempty"`
|
||||
Owner string `json:"owner,omitempty"`
|
||||
ParentPath string `json:"parentPath"`
|
||||
ParentPath string `json:"parentPath,omitempty"`
|
||||
Size int64 `json:"size,omitempty"`
|
||||
WebURL string `json:"webUrl,omitempty"`
|
||||
}
|
||||
@ -363,13 +363,20 @@ type SharePointInfo struct {
|
||||
// Headers returns the human-readable names of properties in a SharePointInfo
|
||||
// for printing out to a terminal in a columnar display.
|
||||
func (i SharePointInfo) Headers() []string {
|
||||
return []string{}
|
||||
return []string{"ItemName", "ParentPath", "Size", "WebURL", "Created", "Modified"}
|
||||
}
|
||||
|
||||
// Values returns the values matching the Headers list for printing
|
||||
// out to a terminal in a columnar display.
|
||||
func (i SharePointInfo) Values() []string {
|
||||
return []string{}
|
||||
return []string{
|
||||
i.ItemName,
|
||||
i.ParentPath,
|
||||
humanize.Bytes(uint64(i.Size)),
|
||||
i.WebURL,
|
||||
common.FormatTabularDisplayTime(i.Created),
|
||||
common.FormatTabularDisplayTime(i.Modified),
|
||||
}
|
||||
}
|
||||
|
||||
// OneDriveInfo describes a oneDrive item
|
||||
@ -393,7 +400,11 @@ func (i OneDriveInfo) Headers() []string {
|
||||
// out to a terminal in a columnar display.
|
||||
func (i OneDriveInfo) Values() []string {
|
||||
return []string{
|
||||
i.ItemName, i.ParentPath, humanize.Bytes(uint64(i.Size)), i.Owner,
|
||||
common.FormatTabularDisplayTime(i.Created), common.FormatTabularDisplayTime(i.Modified),
|
||||
i.ItemName,
|
||||
i.ParentPath,
|
||||
humanize.Bytes(uint64(i.Size)),
|
||||
i.Owner,
|
||||
common.FormatTabularDisplayTime(i.Created),
|
||||
common.FormatTabularDisplayTime(i.Modified),
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,11 +102,18 @@ func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() {
|
||||
RepoRef: "reporef",
|
||||
ShortRef: "deadbeef",
|
||||
ItemInfo: details.ItemInfo{
|
||||
SharePoint: &details.SharePointInfo{},
|
||||
SharePoint: &details.SharePointInfo{
|
||||
ItemName: "itemName",
|
||||
ParentPath: "parentPath",
|
||||
Size: 1000,
|
||||
WebURL: "https://not.a.real/url",
|
||||
Created: now,
|
||||
Modified: now,
|
||||
},
|
||||
},
|
||||
expectHs: []string{"ID"},
|
||||
expectVs: []string{"deadbeef"},
|
||||
},
|
||||
expectHs: []string{"ID", "ItemName", "ParentPath", "Size", "WebURL", "Created", "Modified"},
|
||||
expectVs: []string{"deadbeef", "itemName", "parentPath", "1.0 kB", "https://not.a.real/url", nowStr, nowStr},
|
||||
},
|
||||
{
|
||||
name: "oneDrive info",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user