Skip to content

Commit

Permalink
feat(cli): show summary details
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed Oct 17, 2023
1 parent cc5cbe8 commit 7ef3a94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
13 changes: 9 additions & 4 deletions packages/cli/src/Action/BackupAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createRepo } from "../Factory/RepositoryFactory";
import { createTask } from "../Factory/TaskFactory";
import { PreSnapshot } from "../Repository/RepositoryAbstract";
import { DataFormat } from "../utils/DataFormat";
import { renderError, renderResult } from "../utils/cli";
import { renderError, renderObject, renderResult } from "../utils/cli";
import {
filterPackages,
findRepositoryOrFail,
Expand All @@ -19,7 +19,6 @@ import { runSteps } from "../utils/steps";
import { Streams } from "../utils/stream";
import { GargabeCollector, ensureFreeDiskTempSpace } from "../utils/temp";
import { IfRequireKeys } from "../utils/ts";
import { PruneAction } from "./PruneAction";
import { ok } from "assert";
import chalk from "chalk";
import { randomUUID } from "crypto";
Expand Down Expand Up @@ -180,6 +179,7 @@ export class BackupAction<TRequired extends boolean = true> {
const renderData = (
item: Listr3TaskResultEnd<Context>,
color?: boolean,
result: Listr3TaskResultEnd<Context>[] = [],
) => {
const g = (v: string) => (color ? `${chalk.gray(`(${v})`)}` : `(${v})`);
return item.key === "prune"
Expand All @@ -193,7 +193,12 @@ export class BackupAction<TRequired extends boolean = true> {
: item.key === "copy"
? `${item.data.packageName} ${g(item.data.mirrorRepositoryName)}`
: item.key === "summary"
? `Errors: ${item.data.errors}`
? renderObject({
errors: item.data.errors,
backups: result.filter((r) => !r.error && r.key === "backup")
.length,
copies: result.filter((r) => !r.error && r.key === "copy").length,
})
: item.key === "report"
? item.data.type
: "";
Expand All @@ -207,7 +212,7 @@ export class BackupAction<TRequired extends boolean = true> {
.map((item) => {
const icon = renderResult(item.error, false);
const title = renderTitle(item);
const data = renderData(item, false);
const data = renderData(item, false, result);
return `${icon} ${title}: ${data}`;
}),
table: {
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/src/Action/RestoreAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createTask } from "../Factory/TaskFactory";
import { Snapshot } from "../Repository/RepositoryAbstract";
import { TaskAbstract } from "../Task/TaskAbstract";
import { DataFormat } from "../utils/DataFormat";
import { renderError, renderResult } from "../utils/cli";
import { renderError, renderObject, renderResult } from "../utils/cli";
import {
findPackageOrFail,
findRepositoryOrFail,
Expand Down Expand Up @@ -175,6 +175,7 @@ export class RestoreAction<TRequired extends boolean = true> {
const renderData = (
item: Listr3TaskResultEnd<Context>,
color?: boolean,
result: Listr3TaskResultEnd<Context>[] = [],
) => {
const g = (v: string) => (color ? `${chalk.gray(`(${v})`)}` : `(${v})`);
return item.key === "snapshots"
Expand All @@ -183,6 +184,12 @@ export class RestoreAction<TRequired extends boolean = true> {
? `${item.data.packageName} ${g(item.data.taskName)}`
: item.key === "restore"
? `${item.data.packageName} ${g(item.data.repositoryName)}`
: item.key === "summary"
? renderObject({
errors: item.data.errors,
restores: result.filter((r) => !r.error && r.key === "restore")
.length,
})
: "";
};
return new DataFormat({
Expand All @@ -200,7 +207,7 @@ export class RestoreAction<TRequired extends boolean = true> {
result.map((item) => [
renderResult(item.error),
renderTitle(item, true),
renderData(item, true),
renderData(item, true, result),
duration(item.elapsed),
renderError(item.error, options.verbose),
]),
Expand Down

0 comments on commit 7ef3a94

Please sign in to comment.