-
Notifications
You must be signed in to change notification settings - Fork 0
/
automkv.ts
64 lines (59 loc) · 2.18 KB
/
automkv.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {getExe} from "./utils.ts";
import Runner from "./runner.ts";
import Watcher from "./watcher.ts";
import Job from "./job.ts";
function printUsage() {
console.log("Usage:");
console.log(" automkv watch <file>");
console.log(" Monitor the target 'automkv.yml' file's destination folder for any");
console.log(" changes, and run the edits in the file when any updates have");
console.log(" finished.")
console.log(" automkv watch <folder>");
console.log(" Monitor the target folder (and subfolders) for files ending in");
console.log(" 'automkv.yml'. Any files found will have their destination folders");
console.log(" monitored for changes, and the edits in the file will run when any");
console.log(" updates have finished.");
console.log(" automkv run <target_file>");
console.log(" Apply the edits in a 'automkv.yml' file immediately to all target");
console.log(" files in the target folder");
Deno.exit(0);
}
const mkvpropedit = await getExe("mkvpropedit");
const mkvextract = await getExe("mkvextract");
const runner = new Runner(mkvpropedit, mkvextract);
const watcher = new Watcher(runner);
console.log("Running automkv with versions:");
let process = Deno.run({cmd: [mkvpropedit, "--version"], stdout: "inherit", stderr: "inherit"});
await process.status();
process = Deno.run({cmd: [mkvextract, "--version"], stdout: "inherit", stderr: "inherit"});
await process.status();
console.log();
if (Deno.args.length < 2)
printUsage();
switch (Deno.args[0]) {
case "watch": {
const stat = Deno.statSync(Deno.args[1]);
if (stat.isFile)
await watcher.file(new Job(Deno.args[1])).promise;
if (stat.isDirectory)
await watcher.folder(Deno.args[1]).promise;
console.error("Argument for watch is not a file or directory!");
printUsage();
break;
}
case "run": {
await runner.job(new Job(Deno.args[1]));
break;
}
case "help":
case "--help":
case "-?": {
printUsage();
break;
}
default: {
console.error("Unexpected argument:", Deno.args[0]);
printUsage();
break;
}
}