@datatruck/cli 0.37.0 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/config.schema.json +130 -74
  2. package/lib/actions/BackupAction.d.ts +55 -19
  3. package/lib/actions/BackupAction.js +31 -7
  4. package/lib/actions/CleanCacheAction.d.ts +6 -7
  5. package/lib/actions/CleanCacheAction.js +2 -1
  6. package/lib/actions/ConfigAction.d.ts +3 -5
  7. package/lib/actions/ConfigAction.js +0 -1
  8. package/lib/actions/CopyAction.d.ts +37 -11
  9. package/lib/actions/CopyAction.js +29 -2
  10. package/lib/actions/ExportAction.d.ts +94 -0
  11. package/lib/actions/ExportAction.js +236 -0
  12. package/lib/actions/InitAction.d.ts +17 -7
  13. package/lib/actions/InitAction.js +9 -1
  14. package/lib/actions/PruneAction.d.ts +76 -17
  15. package/lib/actions/PruneAction.js +62 -2
  16. package/lib/actions/RestoreAction.d.ts +55 -21
  17. package/lib/actions/RestoreAction.js +44 -56
  18. package/lib/actions/SnapshotsAction.d.ts +80 -21
  19. package/lib/actions/SnapshotsAction.js +82 -1
  20. package/lib/cli.d.ts +0 -3
  21. package/lib/cli.js +14 -93
  22. package/lib/commands/BackupCommand.d.ts +120 -13
  23. package/lib/commands/BackupCommand.js +22 -50
  24. package/lib/commands/CleanCacheCommand.d.ts +10 -3
  25. package/lib/commands/CleanCacheCommand.js +14 -6
  26. package/lib/commands/CommandAbstract.d.ts +10 -10
  27. package/lib/commands/CommandAbstract.js +6 -9
  28. package/lib/commands/ConfigCommand.d.ts +72 -9
  29. package/lib/commands/ConfigCommand.js +36 -28
  30. package/lib/commands/CopyCommand.d.ts +102 -10
  31. package/lib/commands/CopyCommand.js +18 -40
  32. package/lib/commands/ExportCommand.d.ts +143 -0
  33. package/lib/commands/ExportCommand.js +50 -0
  34. package/lib/commands/InitCommand.d.ts +42 -7
  35. package/lib/commands/InitCommand.js +15 -17
  36. package/lib/commands/PruneCommand.d.ts +237 -17
  37. package/lib/commands/PruneCommand.js +27 -99
  38. package/lib/commands/RestoreCommand.d.ts +126 -13
  39. package/lib/commands/RestoreCommand.js +20 -49
  40. package/lib/commands/RunCommand.d.ts +23 -4
  41. package/lib/commands/RunCommand.js +21 -12
  42. package/lib/commands/SnapshotsCommand.d.ts +240 -23
  43. package/lib/commands/SnapshotsCommand.js +23 -101
  44. package/lib/commands/StartServerCommand.d.ts +10 -3
  45. package/lib/commands/StartServerCommand.js +11 -3
  46. package/lib/repositories/DatatruckRepository.js +1 -1
  47. package/lib/repositories/GitRepository.js +5 -2
  48. package/lib/tasks/MssqlTask.js +1 -1
  49. package/lib/tasks/MysqlDumpTask.js +1 -1
  50. package/lib/tasks/SqlDumpTaskAbstract.js +2 -2
  51. package/lib/utils/cli.d.ts +0 -17
  52. package/lib/utils/cli.js +1 -47
  53. package/lib/utils/datatruck/command.d.ts +6 -5
  54. package/lib/utils/datatruck/command.js +9 -5
  55. package/lib/utils/datatruck/job.js +17 -12
  56. package/lib/utils/datatruck/repository.d.ts +1 -0
  57. package/lib/utils/datatruck/repository.js +8 -1
  58. package/lib/utils/git.d.ts +5 -1
  59. package/lib/utils/git.js +7 -3
  60. package/lib/utils/math.js +1 -1
  61. package/lib/utils/object.d.ts +5 -0
  62. package/lib/utils/object.js +10 -1
  63. package/lib/utils/options.d.ts +24 -0
  64. package/lib/utils/options.js +94 -0
  65. package/lib/utils/progress.js +1 -1
  66. package/lib/utils/restic.js +1 -1
  67. package/lib/utils/string.d.ts +2 -1
  68. package/lib/utils/string.js +5 -1
  69. package/lib/utils/watcher.js +1 -1
  70. package/package.json +4 -4
@@ -48,7 +48,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
48
48
  return (mod && mod.__esModule) ? mod : { "default": mod };
49
49
  };
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.RestoreAction = void 0;
51
+ exports.RestoreAction = exports.restoreActionOptions = void 0;
52
52
  const cli_1 = require("../utils/cli");
53
53
  const data_format_1 = require("../utils/data-format");
54
54
  const config_1 = require("../utils/datatruck/config");
@@ -56,61 +56,40 @@ const repository_1 = require("../utils/datatruck/repository");
56
56
  const task_1 = require("../utils/datatruck/task");
57
57
  const date_1 = require("../utils/date");
58
58
  const error_1 = require("../utils/error");
59
- const fs_1 = require("../utils/fs");
60
59
  const list_1 = require("../utils/list");
60
+ const object_1 = require("../utils/object");
61
61
  const progress_1 = require("../utils/progress");
62
- const string_1 = require("../utils/string");
63
62
  const temp_1 = require("../utils/temp");
64
63
  const SnapshotsAction_1 = require("./SnapshotsAction");
65
64
  const assert_1 = require("assert");
66
65
  const chalk_1 = __importDefault(require("chalk"));
66
+ exports.restoreActionOptions = {
67
+ id: {
68
+ description: "Filter by snapshot id",
69
+ shortFlag: "i",
70
+ required: true,
71
+ },
72
+ ...(0, object_1.pickProps)(SnapshotsAction_1.snapshotsActionOptions, {
73
+ tags: true,
74
+ packageNames: true,
75
+ packageTaskNames: true,
76
+ packageConfig: true,
77
+ repositoryNames: true,
78
+ repositoryTypes: true,
79
+ }),
80
+ initial: {
81
+ description: "Initial restoring (disables restore path)",
82
+ value: "boolean",
83
+ },
84
+ };
67
85
  class RestoreAction {
68
86
  config;
69
87
  options;
70
- taskErrors = {};
71
- repoErrors = {};
72
- constructor(config, options) {
88
+ settings;
89
+ constructor(config, options, settings) {
73
90
  this.config = config;
74
91
  this.options = options;
75
- }
76
- async findSnapshots() {
77
- const result = [];
78
- const filterRepo = (0, string_1.createPatternFilter)(this.options.repositoryNames);
79
- const filterRepoType = (0, string_1.createPatternFilter)(this.options.repositoryTypes);
80
- for (const repository of this.config.repositories) {
81
- if (!filterRepo(repository.name))
82
- continue;
83
- if (!filterRepoType(repository.type))
84
- continue;
85
- const snapshotsAction = new SnapshotsAction_1.SnapshotsAction(this.config, {
86
- repositoryNames: [repository.name],
87
- ids: [this.options.snapshotId],
88
- packageNames: this.options.packageNames,
89
- packageTaskNames: this.options.packageTaskNames,
90
- packageConfig: this.options.packageConfig,
91
- tags: this.options.tags,
92
- });
93
- const snapshots = await snapshotsAction.exec("restore");
94
- result.push(...snapshots.map((ss) => ({
95
- date: ss.date,
96
- id: ss.id,
97
- originalId: ss.originalId,
98
- packageName: ss.packageName,
99
- packageTaskName: ss.packageTaskName,
100
- tags: ss.tags,
101
- repositoryName: repository.name,
102
- })));
103
- }
104
- return result;
105
- }
106
- groupSnapshots(snapshots) {
107
- const names = [];
108
- return snapshots.filter((snapshot) => {
109
- if (names.includes(snapshot.packageName))
110
- return false;
111
- names.push(snapshot.packageName);
112
- return true;
113
- });
92
+ this.settings = settings;
114
93
  }
115
94
  async restore(data) {
116
95
  let { snapshot, pkg, task } = data;
@@ -125,9 +104,8 @@ class RestoreAction {
125
104
  });
126
105
  snapshotPath = taskResult?.snapshotPath;
127
106
  }
128
- await (0, fs_1.initEmptyDir)(snapshotPath);
129
- if (this.config.minFreeDiskSpace)
130
- await (0, fs_1.ensureFreeDiskSpace)([snapshotPath], this.config.minFreeDiskSpace);
107
+ (0, assert_1.ok)(snapshotPath);
108
+ await (0, repository_1.initSnapshotPath)(snapshotPath, this.config.minFreeDiskSpace);
131
109
  await repo.restore({
132
110
  options: this.options,
133
111
  snapshot: data.snapshot,
@@ -182,15 +160,15 @@ class RestoreAction {
182
160
  });
183
161
  }
184
162
  async exec() {
185
- const { options } = this;
163
+ const { options, settings } = this;
186
164
  const gc = new temp_1.GargabeCollector();
187
165
  const pm = new progress_1.ProgressManager({
188
166
  verbose: options.verbose,
189
- tty: options.tty,
190
- mode: options.progress,
167
+ tty: settings.tty,
168
+ mode: settings.progress,
191
169
  });
192
170
  const l = new list_1.Listr3({
193
- streams: options.streams,
171
+ streams: settings.streams,
194
172
  progressManager: pm,
195
173
  gargabeCollector: gc,
196
174
  });
@@ -211,12 +189,22 @@ class RestoreAction {
211
189
  const { minFreeDiskSpace } = this.config;
212
190
  if (minFreeDiskSpace)
213
191
  await (0, temp_1.ensureFreeDiskTempSpace)(minFreeDiskSpace);
214
- if (!options.snapshotId)
192
+ if (!options.id)
215
193
  throw new error_1.AppError("Snapshot id is required");
216
- const snapshots = this.groupSnapshots(await this.findSnapshots());
194
+ const snapshots = await new SnapshotsAction_1.SnapshotsAction(this.config, {
195
+ ids: [this.options.id],
196
+ repositoryNames: this.options.repositoryNames,
197
+ repositoryTypes: this.options.repositoryTypes,
198
+ packageNames: this.options.packageNames,
199
+ packageTaskNames: this.options.packageTaskNames,
200
+ packageConfig: this.options.packageConfig,
201
+ tags: this.options.tags,
202
+ groupBy: ["packageName"],
203
+ last: 1,
204
+ }).exec("restore");
217
205
  if (!snapshots.length)
218
206
  throw new error_1.AppError("None snapshot found");
219
- data.id = options.snapshotId;
207
+ data.id = options.id;
220
208
  data.packages = snapshots.length;
221
209
  return snapshots.map((snapshot) => l.$task({
222
210
  key: "restore",
@@ -233,7 +221,7 @@ class RestoreAction {
233
221
  const env_1 = { stack: [], error: void 0, hasError: false };
234
222
  try {
235
223
  let pkg = (0, config_1.resolvePackage)((0, config_1.findPackageOrFail)(this.config, snapshot.packageName), {
236
- snapshotId: options.snapshotId,
224
+ snapshotId: options.id,
237
225
  snapshotDate: snapshot.date,
238
226
  action: "restore",
239
227
  });
@@ -1,34 +1,93 @@
1
1
  import { Snapshot } from "../repositories/RepositoryAbstract";
2
2
  import type { Config, RepositoryConfigEnabledAction } from "../utils/datatruck/config-type";
3
- import { IfRequireKeys } from "../utils/ts";
3
+ import { InferOptions } from "../utils/options";
4
4
  export type SnapshotGroupByType = keyof Pick<ExtendedSnapshot, "packageName" | "repositoryName" | "repositoryType">;
5
- export type SnapshotsActionOptions = {
6
- ids?: string[];
7
- hostnames?: string[];
8
- repositoryNames?: string[];
9
- packageNames?: string[];
10
- packageTaskNames?: string[];
11
- packageConfig?: boolean;
12
- repositoryTypes?: string[];
5
+ export declare const snapshotsActionOptions: {
6
+ ids: {
7
+ description: string;
8
+ shortFlag: string;
9
+ value: "array";
10
+ };
11
+ repositoryNames: {
12
+ description: string;
13
+ shortFlag: string;
14
+ value: "array";
15
+ };
16
+ repositoryTypes: {
17
+ description: string;
18
+ shortFlag: string;
19
+ value: "array";
20
+ };
21
+ packageNames: {
22
+ description: string;
23
+ shortFlag: string;
24
+ value: "array";
25
+ };
26
+ packageTaskNames: {
27
+ description: string;
28
+ shortFlag: string;
29
+ value: "array";
30
+ };
31
+ tags: {
32
+ description: string;
33
+ shortFlag: string;
34
+ value: "array";
35
+ };
36
+ packageConfig: {
37
+ description: string;
38
+ shortFlag: string;
39
+ };
40
+ hostnames: {
41
+ description: string;
42
+ shortFlag: string;
43
+ value: "array";
44
+ };
45
+ groupBy: {
46
+ description: string;
47
+ shortFlag: string;
48
+ value: (v: string) => ("packageName" | "repositoryName" | "repositoryType" | "id")[];
49
+ };
50
+ last: {
51
+ description: string;
52
+ shortFlag: string;
53
+ value: "number";
54
+ };
55
+ lastMinutely: {
56
+ description: string;
57
+ value: "number";
58
+ };
59
+ lastDaily: {
60
+ description: string;
61
+ value: "number";
62
+ };
63
+ lastHourly: {
64
+ description: string;
65
+ value: "number";
66
+ };
67
+ lastMonthly: {
68
+ description: string;
69
+ value: "number";
70
+ };
71
+ lastWeekly: {
72
+ description: string;
73
+ value: "number";
74
+ };
75
+ lastYearly: {
76
+ description: string;
77
+ value: "number";
78
+ };
79
+ };
80
+ export type SnapshotsActionOptions = InferOptions<typeof snapshotsActionOptions> & {
13
81
  verbose?: boolean;
14
- tags?: string[];
15
- last?: number;
16
- lastMinutely?: number;
17
- lastHourly?: number;
18
- lastDaily?: number;
19
- lastWeekly?: number;
20
- lastMonthly?: number;
21
- lastYearly?: number;
22
- groupBy?: SnapshotGroupByType[];
23
82
  };
24
83
  export type ExtendedSnapshot = {
25
84
  shortId: string;
26
85
  repositoryName: string;
27
86
  repositoryType: string;
28
87
  } & Snapshot;
29
- export declare class SnapshotsAction<TRequired extends boolean = true> {
88
+ export declare class SnapshotsAction {
30
89
  readonly config: Config;
31
- readonly options: IfRequireKeys<TRequired, SnapshotsActionOptions>;
32
- constructor(config: Config, options: IfRequireKeys<TRequired, SnapshotsActionOptions>);
90
+ readonly options: SnapshotsActionOptions;
91
+ constructor(config: Config, options: SnapshotsActionOptions);
33
92
  exec(sourceAction?: RepositoryConfigEnabledAction): Promise<ExtendedSnapshot[]>;
34
93
  }
@@ -1,10 +1,91 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SnapshotsAction = void 0;
3
+ exports.SnapshotsAction = exports.snapshotsActionOptions = void 0;
4
4
  const config_1 = require("../utils/datatruck/config");
5
5
  const repository_1 = require("../utils/datatruck/repository");
6
6
  const snapshot_1 = require("../utils/datatruck/snapshot");
7
7
  const string_1 = require("../utils/string");
8
+ const groupByValues = [
9
+ "id",
10
+ "packageName",
11
+ "repositoryName",
12
+ "repositoryType",
13
+ ];
14
+ exports.snapshotsActionOptions = {
15
+ ids: {
16
+ description: "Filter by identifiers",
17
+ shortFlag: "i",
18
+ value: "array",
19
+ },
20
+ repositoryNames: {
21
+ description: "Filter by repository names",
22
+ shortFlag: "r",
23
+ value: "array",
24
+ },
25
+ repositoryTypes: {
26
+ description: "Filter by repository types",
27
+ shortFlag: "rt",
28
+ value: "array",
29
+ },
30
+ packageNames: {
31
+ description: "Filter by package names",
32
+ shortFlag: "p",
33
+ value: "array",
34
+ },
35
+ packageTaskNames: {
36
+ description: "Filter by task names",
37
+ shortFlag: "pt",
38
+ value: "array",
39
+ },
40
+ tags: {
41
+ description: "Filter by tags",
42
+ shortFlag: "t",
43
+ value: "array",
44
+ },
45
+ packageConfig: {
46
+ description: "Filter by package config",
47
+ shortFlag: "pc",
48
+ },
49
+ hostnames: {
50
+ description: "Filter by hostnames",
51
+ shortFlag: "h",
52
+ value: "array",
53
+ },
54
+ groupBy: {
55
+ description: `Group by values (${groupByValues.join(", ")})`,
56
+ shortFlag: "g",
57
+ value: (v) => (0, string_1.parseStringList)(v, groupByValues),
58
+ },
59
+ last: {
60
+ description: "Filter by last snapshots",
61
+ shortFlag: "l",
62
+ value: "number",
63
+ },
64
+ lastMinutely: {
65
+ description: "Filter by last minutely",
66
+ value: "number",
67
+ },
68
+ lastDaily: {
69
+ description: "Filter by last daily",
70
+ value: "number",
71
+ },
72
+ lastHourly: {
73
+ description: "Filter by last hourly",
74
+ value: "number",
75
+ },
76
+ lastMonthly: {
77
+ description: "Filter by last monthly",
78
+ value: "number",
79
+ },
80
+ lastWeekly: {
81
+ description: "Filter by last weekly",
82
+ value: "number",
83
+ },
84
+ lastYearly: {
85
+ description: "Filter by last yearly",
86
+ value: "number",
87
+ },
88
+ };
8
89
  class SnapshotsAction {
9
90
  config;
10
91
  options;
package/lib/cli.d.ts CHANGED
@@ -1,4 +1 @@
1
- import { DatatruckCommandMap, InferDatatruckCommandOptions } from "./utils/datatruck/command";
2
- export declare function buildArgs<T extends keyof DatatruckCommandMap>(input: T, options: InferDatatruckCommandOptions<T>): any[];
3
1
  export declare function parseArgs(args: string[]): void;
4
- export declare function exec<T extends keyof DatatruckCommandMap>(input: T, options: InferDatatruckCommandOptions<T>): Promise<void>;
package/lib/cli.js CHANGED
@@ -1,32 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.exec = exports.parseArgs = exports.buildArgs = void 0;
6
+ exports.parseArgs = void 0;
30
7
  const ConfigAction_1 = require("./actions/ConfigAction");
31
8
  const globalData_1 = __importDefault(require("./globalData"));
32
9
  const cli_1 = require("./utils/cli");
@@ -34,9 +11,9 @@ const command_1 = require("./utils/datatruck/command");
34
11
  const error_1 = require("./utils/error");
35
12
  const exit_1 = require("./utils/exit");
36
13
  const fs_1 = require("./utils/fs");
37
- const string_1 = require("./utils/string");
14
+ const options_1 = require("./utils/options");
38
15
  const temp_1 = require("./utils/temp");
39
- const chalk_1 = __importStar(require("chalk"));
16
+ const chalk_1 = __importDefault(require("chalk"));
40
17
  const commander_1 = require("commander");
41
18
  const fs_2 = require("fs");
42
19
  const path_1 = require("path");
@@ -49,46 +26,7 @@ function getGlobalOptions() {
49
26
  progress: parseBool(result.progress),
50
27
  };
51
28
  }
52
- function makeCommand(command) {
53
- const instance = (0, command_1.createCommand)(command, getGlobalOptions(), null);
54
- const options = instance.optionsConfig();
55
- const inlineOptions = [];
56
- for (const name in options) {
57
- const option = options[name];
58
- if (typeof option.option !== "string") {
59
- inlineOptions.push({ name, required: option.required });
60
- }
61
- }
62
- const programCommand = program.command([
63
- command,
64
- ...inlineOptions.map((v) => (v.required ? `<${v.name}>` : `[${v.name}]`)),
65
- ].join(" "));
66
- for (const key in options) {
67
- const option = options[key];
68
- if (typeof option.option === "string") {
69
- const description = `${option.description}${option.defaults ? ` (defaults: ${option.defaults})` : ""}`;
70
- if (option.required) {
71
- programCommand.requiredOption(option.option, description);
72
- }
73
- else {
74
- programCommand.option(option.option, description);
75
- }
76
- }
77
- }
78
- return programCommand.action(async (...args) => {
79
- const inlineValues = args.slice(0, inlineOptions.length);
80
- const action = makeCommandAction(command);
81
- const inOptions = args[inlineOptions.length] || {};
82
- const options = inlineOptions.reduce((result, inlineOption, index) => {
83
- const value = inlineValues[index];
84
- if (value !== undefined)
85
- result[inlineOption.name] = value;
86
- return result;
87
- }, inOptions);
88
- return await action(options);
89
- });
90
- }
91
- function makeCommandAction(commandName) {
29
+ function createCommandAction(Constructor) {
92
30
  return async function (options) {
93
31
  let exitCode = 1;
94
32
  let error;
@@ -100,7 +38,7 @@ function makeCommandAction(commandName) {
100
38
  globalData_1.default.tempDir = (0, path_1.isAbsolute)(config.data.tempDir)
101
39
  ? config.data.tempDir
102
40
  : (0, path_1.join)((0, path_1.dirname)(config.path), config.data.tempDir);
103
- const command = (0, command_1.createCommand)(commandName, { ...globalOptions }, options, {}, globalOptions.config);
41
+ const command = new Constructor({ ...globalOptions }, options, {}, globalOptions.config);
104
42
  const response = await command.exec();
105
43
  errors = response.errors;
106
44
  exitCode = response.exitCode;
@@ -118,18 +56,18 @@ function makeCommandAction(commandName) {
118
56
  }
119
57
  if (error) {
120
58
  if (globalOptions.verbose) {
121
- console.error((0, chalk_1.red)(error.stack));
59
+ console.error(chalk_1.default.red(error.stack));
122
60
  }
123
61
  else {
124
62
  if (error instanceof error_1.AppError) {
125
- console.error((0, chalk_1.red)(error.message));
63
+ console.error(chalk_1.default.red(error.message));
126
64
  }
127
65
  else {
128
- console.error((0, chalk_1.red)(error.stack));
66
+ console.error(chalk_1.default.red(error.stack));
129
67
  }
130
68
  }
131
69
  }
132
- await (0, cli_1.waitForStdDrain)(5000);
70
+ await (0, cli_1.waitForStdDrain)(5_000);
133
71
  process.exit(exitCode);
134
72
  };
135
73
  }
@@ -145,24 +83,12 @@ program.option("-c,--config <path>", "Config path", process.env["DATATRUCK_CONFI
145
83
  program.option("--tty <value>", "TTY mode (auto, true, false)", "auto");
146
84
  program.option("--progress <value>", "Progress type (auto, true, false, interval, interval:[ms])", "auto");
147
85
  program.option("-o,--output-format <format>", "Output format (json, pjson, yaml, table, custom=$, tpl=name)", "table");
148
- makeCommand("startServer").alias("start");
149
- makeCommand("config").alias("c");
150
- makeCommand("init").alias("i");
151
- makeCommand("snapshots").alias("s");
152
- makeCommand("prune").alias("p");
153
- makeCommand("backup").alias("b");
154
- makeCommand("restore").alias("r");
155
- makeCommand("run");
156
- makeCommand("copy").alias("cp");
157
- makeCommand("cleanCache").alias("cc");
158
- function buildArgs(input, options) {
159
- const optionsArray = Object.keys(options).flatMap((name) => [
160
- `--${(0, string_1.snakeCase)(name, "-")}`,
161
- options[name],
162
- ]);
163
- return [input, ...optionsArray];
86
+ const Commands = Object.values(command_1.datatruckCommands)
87
+ .map((Command) => ({ Command, config: Command.config() }))
88
+ .sort((a, b) => a.config.name.localeCompare(b.config.name));
89
+ for (const { Command, config } of Commands) {
90
+ program.addCommand((0, options_1.createCommand)(config, createCommandAction(Command)));
164
91
  }
165
- exports.buildArgs = buildArgs;
166
92
  function parseArgs(args) {
167
93
  program.parse(args);
168
94
  const verbose = getGlobalOptions().verbose;
@@ -187,8 +113,3 @@ function parseArgs(args) {
187
113
  });
188
114
  }
189
115
  exports.parseArgs = parseArgs;
190
- async function exec(input, options) {
191
- const argv = buildArgs(input, options);
192
- return parseArgs(argv);
193
- }
194
- exports.exec = exec;
@@ -1,18 +1,125 @@
1
- import type { RepositoryConfig } from "../utils/datatruck/config-type";
2
- import { If } from "../utils/ts";
1
+ import { InferOptions } from "../utils/options";
3
2
  import { CommandAbstract } from "./CommandAbstract";
4
- export type BackupCommandOptions<TResolved = false> = {
5
- package?: If<TResolved, string[]>;
6
- packageTask?: If<TResolved, string[]>;
7
- repository?: If<TResolved, string[]>;
8
- repositoryType?: If<TResolved, RepositoryConfig["type"][]>;
9
- tag?: If<TResolved, string[]>;
10
- dryRun?: boolean;
11
- date?: string;
12
- prune?: boolean;
3
+ export declare const backupCommandOptions: {
4
+ dryRun: {
5
+ description: string;
6
+ value: "boolean";
7
+ };
8
+ date: {
9
+ description: string;
10
+ };
11
+ prune: {
12
+ description: string;
13
+ value: "boolean";
14
+ };
15
+ repositoryNames: {
16
+ description: string;
17
+ shortFlag: string;
18
+ value: "array";
19
+ };
20
+ repositoryTypes: {
21
+ description: string;
22
+ shortFlag: string;
23
+ value: "array";
24
+ };
25
+ packageNames: {
26
+ description: string;
27
+ shortFlag: string;
28
+ value: "array";
29
+ };
30
+ packageTaskNames: {
31
+ description: string;
32
+ shortFlag: string;
33
+ value: "array";
34
+ };
35
+ tags: {
36
+ description: string;
37
+ shortFlag: string;
38
+ value: "array";
39
+ };
13
40
  };
14
- export declare class BackupCommand extends CommandAbstract<BackupCommandOptions<false>, BackupCommandOptions<true>> {
15
- optionsConfig(): import("../utils/cli").OptionsConfig<BackupCommandOptions<false>, BackupCommandOptions<true>>;
41
+ export type BackupCommandOptions = InferOptions<typeof backupCommandOptions>;
42
+ export declare class BackupCommand extends CommandAbstract<typeof backupCommandOptions> {
43
+ static config(): {
44
+ name: string;
45
+ alias: string;
46
+ options: {
47
+ dryRun: {
48
+ description: string;
49
+ value: "boolean";
50
+ };
51
+ date: {
52
+ description: string;
53
+ };
54
+ prune: {
55
+ description: string;
56
+ value: "boolean";
57
+ };
58
+ repositoryNames: {
59
+ description: string;
60
+ shortFlag: string;
61
+ value: "array";
62
+ };
63
+ repositoryTypes: {
64
+ description: string;
65
+ shortFlag: string;
66
+ value: "array";
67
+ };
68
+ packageNames: {
69
+ description: string;
70
+ shortFlag: string;
71
+ value: "array";
72
+ };
73
+ packageTaskNames: {
74
+ description: string;
75
+ shortFlag: string;
76
+ value: "array";
77
+ };
78
+ tags: {
79
+ description: string;
80
+ shortFlag: string;
81
+ value: "array";
82
+ };
83
+ };
84
+ };
85
+ get optionsConfig(): {
86
+ dryRun: {
87
+ description: string;
88
+ value: "boolean";
89
+ };
90
+ date: {
91
+ description: string;
92
+ };
93
+ prune: {
94
+ description: string;
95
+ value: "boolean";
96
+ };
97
+ repositoryNames: {
98
+ description: string;
99
+ shortFlag: string;
100
+ value: "array";
101
+ };
102
+ repositoryTypes: {
103
+ description: string;
104
+ shortFlag: string;
105
+ value: "array";
106
+ };
107
+ packageNames: {
108
+ description: string;
109
+ shortFlag: string;
110
+ value: "array";
111
+ };
112
+ packageTaskNames: {
113
+ description: string;
114
+ shortFlag: string;
115
+ value: "array";
116
+ };
117
+ tags: {
118
+ description: string;
119
+ shortFlag: string;
120
+ value: "array";
121
+ };
122
+ };
16
123
  exec(): Promise<{
17
124
  result: (import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<{
18
125
  snapshot: {