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,40 +54,25 @@ func IncludeSharePointRestoreDataSelectors(
|
|||||||
sel *selectors.SharePointRestore,
|
sel *selectors.SharePointRestore,
|
||||||
opts SharePointOpts,
|
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
|
if ls == 0 {
|
||||||
// is specified
|
|
||||||
if lp+ln == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(opts.Sites) == 0 {
|
|
||||||
opts.Sites = selectors.Any()
|
opts.Sites = selectors.Any()
|
||||||
}
|
}
|
||||||
|
|
||||||
if lp+ln+lwu == 0 {
|
if lp+li+lwu == 0 {
|
||||||
sel.Include(sel.Sites(opts.Sites))
|
sel.Include(sel.Sites(opts.Sites))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.LibraryPaths = trimFolderSlash(opts.LibraryPaths)
|
if lp+li > 0 {
|
||||||
|
if li == 0 {
|
||||||
if ln == 0 {
|
|
||||||
opts.LibraryItems = selectors.Any()
|
opts.LibraryItems = selectors.Any()
|
||||||
}
|
}
|
||||||
|
|
||||||
containsURLs, suffixURLs := splitFoldersIntoContainsAndPrefix(opts.WebURLs)
|
opts.LibraryPaths = trimFolderSlash(opts.LibraryPaths)
|
||||||
|
|
||||||
if len(containsURLs) > 0 {
|
|
||||||
sel.Include(sel.WebURL(containsURLs))
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(suffixURLs) > 0 {
|
|
||||||
sel.Include(sel.WebURL(suffixURLs, selectors.SuffixMatch()))
|
|
||||||
}
|
|
||||||
|
|
||||||
containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.LibraryPaths)
|
containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.LibraryPaths)
|
||||||
|
|
||||||
if len(containsFolders) > 0 {
|
if len(containsFolders) > 0 {
|
||||||
@ -99,6 +84,20 @@ func IncludeSharePointRestoreDataSelectors(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if lwu > 0 {
|
||||||
|
opts.WebURLs = trimFolderSlash(opts.WebURLs)
|
||||||
|
containsURLs, suffixURLs := splitFoldersIntoContainsAndPrefix(opts.WebURLs)
|
||||||
|
|
||||||
|
if len(containsURLs) > 0 {
|
||||||
|
sel.Include(sel.WebURL(containsURLs))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(suffixURLs) > 0 {
|
||||||
|
sel.Include(sel.WebURL(suffixURLs, selectors.SuffixMatch()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FilterSharePointRestoreInfoSelectors builds the common info-selector filters.
|
// FilterSharePointRestoreInfoSelectors builds the common info-selector filters.
|
||||||
func FilterSharePointRestoreInfoSelectors(
|
func FilterSharePointRestoreInfoSelectors(
|
||||||
sel *selectors.SharePointRestore,
|
sel *selectors.SharePointRestore,
|
||||||
|
|||||||
@ -19,8 +19,6 @@ func TestSharePointUtilsSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
|
func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
|
||||||
suite.T().Skip("just until next PR")
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
empty = []string{}
|
empty = []string{}
|
||||||
single = []string{"single"}
|
single = []string{"single"}
|
||||||
@ -43,7 +41,7 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
|
|||||||
Sites: empty,
|
Sites: empty,
|
||||||
WebURLs: empty,
|
WebURLs: empty,
|
||||||
},
|
},
|
||||||
expectIncludeLen: 0,
|
expectIncludeLen: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "single inputs",
|
name: "single inputs",
|
||||||
@ -53,7 +51,7 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
|
|||||||
Sites: single,
|
Sites: single,
|
||||||
WebURLs: single,
|
WebURLs: single,
|
||||||
},
|
},
|
||||||
expectIncludeLen: 1,
|
expectIncludeLen: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multi inputs",
|
name: "multi inputs",
|
||||||
@ -63,7 +61,7 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
|
|||||||
Sites: multi,
|
Sites: multi,
|
||||||
WebURLs: multi,
|
WebURLs: multi,
|
||||||
},
|
},
|
||||||
expectIncludeLen: 1,
|
expectIncludeLen: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "library contains",
|
name: "library contains",
|
||||||
|
|||||||
@ -355,7 +355,7 @@ type SharePointInfo struct {
|
|||||||
ItemType ItemType `json:"itemType,omitempty"`
|
ItemType ItemType `json:"itemType,omitempty"`
|
||||||
Modified time.Time `josn:"modified,omitempty"`
|
Modified time.Time `josn:"modified,omitempty"`
|
||||||
Owner string `json:"owner,omitempty"`
|
Owner string `json:"owner,omitempty"`
|
||||||
ParentPath string `json:"parentPath"`
|
ParentPath string `json:"parentPath,omitempty"`
|
||||||
Size int64 `json:"size,omitempty"`
|
Size int64 `json:"size,omitempty"`
|
||||||
WebURL string `json:"webUrl,omitempty"`
|
WebURL string `json:"webUrl,omitempty"`
|
||||||
}
|
}
|
||||||
@ -363,13 +363,20 @@ type SharePointInfo struct {
|
|||||||
// Headers returns the human-readable names of properties in a SharePointInfo
|
// Headers returns the human-readable names of properties in a SharePointInfo
|
||||||
// for printing out to a terminal in a columnar display.
|
// for printing out to a terminal in a columnar display.
|
||||||
func (i SharePointInfo) Headers() []string {
|
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
|
// Values returns the values matching the Headers list for printing
|
||||||
// out to a terminal in a columnar display.
|
// out to a terminal in a columnar display.
|
||||||
func (i SharePointInfo) Values() []string {
|
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
|
// OneDriveInfo describes a oneDrive item
|
||||||
@ -393,7 +400,11 @@ func (i OneDriveInfo) Headers() []string {
|
|||||||
// out to a terminal in a columnar display.
|
// out to a terminal in a columnar display.
|
||||||
func (i OneDriveInfo) Values() []string {
|
func (i OneDriveInfo) Values() []string {
|
||||||
return []string{
|
return []string{
|
||||||
i.ItemName, i.ParentPath, humanize.Bytes(uint64(i.Size)), i.Owner,
|
i.ItemName,
|
||||||
common.FormatTabularDisplayTime(i.Created), common.FormatTabularDisplayTime(i.Modified),
|
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",
|
RepoRef: "reporef",
|
||||||
ShortRef: "deadbeef",
|
ShortRef: "deadbeef",
|
||||||
ItemInfo: details.ItemInfo{
|
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",
|
name: "oneDrive info",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user