@datatruck/restic 0.0.3 → 0.0.4
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.
- package/lib/actions/run.d.ts +8 -0
- package/lib/actions/run.js +11 -0
- package/lib/create-bin.js +29 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Action } from "./base.js";
|
|
2
|
+
import { spawnSync } from "child_process";
|
|
3
|
+
export class Run extends Action {
|
|
4
|
+
async run(options) {
|
|
5
|
+
const [restic] = this.cm.createRestic(options.repository, this.verbose);
|
|
6
|
+
const p = restic["createProcess"](options.args, { $log: true });
|
|
7
|
+
const exit = spawnSync(p["command"], p["argv"]?.map((v) => v.toString()), { stdio: "inherit", env: p["options"]?.env });
|
|
8
|
+
if (exit.status)
|
|
9
|
+
process.exit(exit.status);
|
|
10
|
+
}
|
|
11
|
+
}
|
package/lib/create-bin.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Copy } from "./actions/copy.js";
|
|
|
3
3
|
import { Create } from "./actions/create.js";
|
|
4
4
|
import { Init } from "./actions/init.js";
|
|
5
5
|
import { Prune } from "./actions/prune.js";
|
|
6
|
+
import { Run } from "./actions/run.js";
|
|
6
7
|
import { parseConfigFile } from "./config.js";
|
|
7
8
|
import { parseStringList } from "@datatruck/cli/utils/string.js";
|
|
8
9
|
import { Command } from "commander";
|
|
@@ -32,6 +33,18 @@ export function createBin(inConfig) {
|
|
|
32
33
|
const create = new Create();
|
|
33
34
|
await create.run(options);
|
|
34
35
|
});
|
|
36
|
+
program
|
|
37
|
+
.command("run", {})
|
|
38
|
+
.description("Run arbitrary restic command")
|
|
39
|
+
.argument("<repository>", "Repository name")
|
|
40
|
+
.argument("[args...]", "Restic arguments")
|
|
41
|
+
.allowUnknownOption()
|
|
42
|
+
.allowExcessArguments()
|
|
43
|
+
.action(async (repository, args) => {
|
|
44
|
+
const { config, globalOptions } = await load();
|
|
45
|
+
const run = new Run(config, globalOptions);
|
|
46
|
+
await run.run({ repository, args });
|
|
47
|
+
});
|
|
35
48
|
program
|
|
36
49
|
.command("init")
|
|
37
50
|
.alias("i")
|
|
@@ -79,5 +92,21 @@ export function createBin(inConfig) {
|
|
|
79
92
|
const prune = new Prune(config, globalOptions);
|
|
80
93
|
await prune.run(options);
|
|
81
94
|
});
|
|
95
|
+
const parse = program.parse.bind(program);
|
|
96
|
+
program.parse = function (args, options) {
|
|
97
|
+
if (!args)
|
|
98
|
+
args = process.argv;
|
|
99
|
+
const [node, script, ...rest] = args;
|
|
100
|
+
const commandIndex = rest.findIndex((v) => !v.startsWith("-"));
|
|
101
|
+
const command = rest[commandIndex];
|
|
102
|
+
if (command === "run") {
|
|
103
|
+
args = [
|
|
104
|
+
node,
|
|
105
|
+
script,
|
|
106
|
+
...rest.flatMap((value, index) => commandIndex === index ? [value, "--"] : value),
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
return parse(args, options);
|
|
110
|
+
};
|
|
82
111
|
return program;
|
|
83
112
|
}
|