diff --git a/CHANGELOG.md b/CHANGELOG.md index c8749a5f8..50c391c64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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 ## [v0.8.0] (beta) - 2023-05-15 diff --git a/src/cli/print/print.go b/src/cli/print/print.go index 91ef1e581..633171400 100644 --- a/src/cli/print/print.go +++ b/src/cli/print/print.go @@ -14,6 +14,7 @@ import ( var ( outputAsJSON bool outputAsJSONDebug bool + outputVerbose bool ) type rootCmdCtx struct{} @@ -48,6 +49,7 @@ func AddOutputFlag(cmd *cobra.Command) { 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") 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. @@ -55,6 +57,11 @@ func DisplayJSONFormat() bool { 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 // cmd. Returns nil if no root command is seeded. func StderrWriter(ctx context.Context) io.Writer { diff --git a/src/cli/restore/exchange.go b/src/cli/restore/exchange.go index 1f80958ab..3ad22fbb2 100644 --- a/src/cli/restore/exchange.go +++ b/src/cli/restore/exchange.go @@ -116,7 +116,7 @@ func restoreExchangeCmd(cmd *cobra.Command, args []string) error { return Only(ctx, clues.Wrap(err, "Failed to run Exchange restore")) } - ds.Items().PrintEntries(ctx) + ds.Items().MaybePrintEntries(ctx) return nil } diff --git a/src/cli/restore/onedrive.go b/src/cli/restore/onedrive.go index a3724229e..90caf57df 100644 --- a/src/cli/restore/onedrive.go +++ b/src/cli/restore/onedrive.go @@ -117,7 +117,7 @@ func restoreOneDriveCmd(cmd *cobra.Command, args []string) error { return Only(ctx, clues.Wrap(err, "Failed to run OneDrive restore")) } - ds.Items().PrintEntries(ctx) + ds.Items().MaybePrintEntries(ctx) return nil } diff --git a/src/cli/restore/sharepoint.go b/src/cli/restore/sharepoint.go index 63678a718..332805d8d 100644 --- a/src/cli/restore/sharepoint.go +++ b/src/cli/restore/sharepoint.go @@ -122,7 +122,7 @@ func restoreSharePointCmd(cmd *cobra.Command, args []string) error { return Only(ctx, clues.Wrap(err, "Failed to run SharePoint restore")) } - ds.Items().PrintEntries(ctx) + ds.Items().MaybePrintEntries(ctx) return nil } diff --git a/src/pkg/backup/details/details.go b/src/pkg/backup/details/details.go index dde3bfc8b..483594079 100644 --- a/src/pkg/backup/details/details.go +++ b/src/pkg/backup/details/details.go @@ -20,6 +20,10 @@ import ( "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 // 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 @@ -475,6 +479,20 @@ func (ents entrySet) PrintEntries(ctx context.Context) { 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 type Entry struct { // RepoRef is the full storage path of the item in Kopia