Do not print all the restored items if there are a lot of them (#3495)
For large restore, it just ends up printing a lot of text. This change makes it print a summary instead. We still retain printing the full content if the user asks for a json output as we assume they would be piping it somewhere. ``` Connecting to repository: 1s done Restoring to folder Corso_Restore_24-May-2023_11-49-44 Connecting to M365: done Restoring ∙ 7ceb8e03-bdc5-4509-a136-457526165ec0 Discovered 3 items in backup d5c07808-545d-4906-9ade-f224ca8f13de to restore Enumerating items in repository: 0s done Restoring data: 54s done Restored 304 items. ``` --- #### Does this PR need a docs update or release note? - [x] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [ ] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #<issue> #### Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
631dc477c6
commit
8d68bacfb7
@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Fix Exchange folder cache population error when parent folder isn't found.
|
- Fix Exchange folder cache population error when parent folder isn't found.
|
||||||
- Fix Exchange backup issue caused by incorrect json serialization
|
- Fix Exchange backup issue caused by incorrect json serialization
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Do not display all the items that we restored at the end if there are more than 15. You can override this with `--verbose`.
|
||||||
|
|
||||||
### Known Issues
|
### Known Issues
|
||||||
|
|
||||||
## [v0.8.0] (beta) - 2023-05-15
|
## [v0.8.0] (beta) - 2023-05-15
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
outputAsJSON bool
|
outputAsJSON bool
|
||||||
outputAsJSONDebug bool
|
outputAsJSONDebug bool
|
||||||
|
outputVerbose bool
|
||||||
)
|
)
|
||||||
|
|
||||||
type rootCmdCtx struct{}
|
type rootCmdCtx struct{}
|
||||||
@ -48,6 +49,7 @@ func AddOutputFlag(cmd *cobra.Command) {
|
|||||||
fs.BoolVar(&outputAsJSON, "json", false, "output data in JSON format")
|
fs.BoolVar(&outputAsJSON, "json", false, "output data in JSON format")
|
||||||
fs.BoolVar(&outputAsJSONDebug, "json-debug", false, "output all internal and debugging data in JSON format")
|
fs.BoolVar(&outputAsJSONDebug, "json-debug", false, "output all internal and debugging data in JSON format")
|
||||||
cobra.CheckErr(fs.MarkHidden("json-debug"))
|
cobra.CheckErr(fs.MarkHidden("json-debug"))
|
||||||
|
fs.BoolVar(&outputVerbose, "verbose", false, "don't hide additional information")
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisplayJSONFormat returns true if the printer plans to output as json.
|
// DisplayJSONFormat returns true if the printer plans to output as json.
|
||||||
@ -55,6 +57,11 @@ func DisplayJSONFormat() bool {
|
|||||||
return outputAsJSON || outputAsJSONDebug
|
return outputAsJSON || outputAsJSONDebug
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DisplayVerbose returns true if verbose output is enabled
|
||||||
|
func DisplayVerbose() bool {
|
||||||
|
return outputVerbose
|
||||||
|
}
|
||||||
|
|
||||||
// StderrWriter returns the stderr writer used in the root
|
// StderrWriter returns the stderr writer used in the root
|
||||||
// cmd. Returns nil if no root command is seeded.
|
// cmd. Returns nil if no root command is seeded.
|
||||||
func StderrWriter(ctx context.Context) io.Writer {
|
func StderrWriter(ctx context.Context) io.Writer {
|
||||||
|
|||||||
@ -116,7 +116,7 @@ func restoreExchangeCmd(cmd *cobra.Command, args []string) error {
|
|||||||
return Only(ctx, clues.Wrap(err, "Failed to run Exchange restore"))
|
return Only(ctx, clues.Wrap(err, "Failed to run Exchange restore"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ds.Items().PrintEntries(ctx)
|
ds.Items().MaybePrintEntries(ctx)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,7 +117,7 @@ func restoreOneDriveCmd(cmd *cobra.Command, args []string) error {
|
|||||||
return Only(ctx, clues.Wrap(err, "Failed to run OneDrive restore"))
|
return Only(ctx, clues.Wrap(err, "Failed to run OneDrive restore"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ds.Items().PrintEntries(ctx)
|
ds.Items().MaybePrintEntries(ctx)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,7 +122,7 @@ func restoreSharePointCmd(cmd *cobra.Command, args []string) error {
|
|||||||
return Only(ctx, clues.Wrap(err, "Failed to run SharePoint restore"))
|
return Only(ctx, clues.Wrap(err, "Failed to run SharePoint restore"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ds.Items().PrintEntries(ctx)
|
ds.Items().MaybePrintEntries(ctx)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,10 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Max number of items for which we will print details. If there are
|
||||||
|
// more than this, then we just show a summary.
|
||||||
|
const maxPrintLimit = 15
|
||||||
|
|
||||||
// LocationIDer provides access to location information but guarantees that it
|
// LocationIDer provides access to location information but guarantees that it
|
||||||
// can also generate a unique location (among items in the same service but
|
// can also generate a unique location (among items in the same service but
|
||||||
// possibly across data types within the service) that can be used as a key in
|
// possibly across data types within the service) that can be used as a key in
|
||||||
@ -475,6 +479,20 @@ func (ents entrySet) PrintEntries(ctx context.Context) {
|
|||||||
printEntries(ctx, ents)
|
printEntries(ctx, ents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MaybePrintEntries is same as PrintEntries, but only prints if we
|
||||||
|
// have less than 15 items or is not json output.
|
||||||
|
func (ents entrySet) MaybePrintEntries(ctx context.Context) {
|
||||||
|
if len(ents) > maxPrintLimit &&
|
||||||
|
!print.DisplayJSONFormat() &&
|
||||||
|
!print.DisplayVerbose() {
|
||||||
|
// TODO: Should we detect if the user is piping the output and
|
||||||
|
// print if that is the case?
|
||||||
|
print.Outf(ctx, "Restored %d items.", len(ents))
|
||||||
|
} else {
|
||||||
|
printEntries(ctx, ents)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Entry describes a single item stored in a Backup
|
// Entry describes a single item stored in a Backup
|
||||||
type Entry struct {
|
type Entry struct {
|
||||||
// RepoRef is the full storage path of the item in Kopia
|
// RepoRef is the full storage path of the item in Kopia
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user