-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathapp.ts
More file actions
executable file
·69 lines (65 loc) · 1.91 KB
/
app.ts
File metadata and controls
executable file
·69 lines (65 loc) · 1.91 KB
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
65
66
67
68
69
#!/usr/bin/env -S pkgx --quiet deno^2 run -A
//TODO if you step into dev-dir/subdir and type `dev` does it find the root properly?
//TODO dev off uses PWD which may not be correct if in subdir (obv)
import { Path } from "libpkgx";
import shellcode, { datadir } from "./src/shellcode().ts";
import app_version from "./src/app-version.ts";
import integrate from "./src/integrate.ts";
import { parseArgs } from "jsr:@std/cli@^1/parse-args";
import dump from "./src/dump.ts";
import sniff from "./src/sniff.ts";
const parsedArgs = parseArgs(Deno.args, {
alias: {
n: "dry-run",
"just-print": "dry-run",
recon: "dry-run",
v: "version",
h: "help",
q: "quiet",
},
collect: ["quiet"],
boolean: ["help", "version", "shellcode", "quiet"],
default: {
"dry-run": false,
},
});
if (parsedArgs.help) {
const status = await new Deno.Command("pkgx", {
args: ["--quiet", "gh", "repo", "view", "pkgxdev/dev"],
}).spawn().status;
Deno.exit(status.code);
} else if (parsedArgs.shellcode) {
console.log(shellcode());
} else if (parsedArgs.version) {
console.log(`dev ${app_version}`);
} else {
const subcommand = parsedArgs._[0];
const dryrun = parsedArgs["dry-run"] as boolean;
const quiet = parsedArgs["quiet"] != undefined;
switch (subcommand) {
case "integrate":
await integrate("install", { dryrun });
break;
case "deintegrate":
await integrate("uninstall", { dryrun });
break;
case "status":
{
const cwd = Path.cwd();
if (
datadir().join(cwd.string.slice(1), "dev.pkgx.activated").isFile()
) {
//FIXME probably slower than necessary
const { pkgs } = await sniff(cwd);
Deno.exit(pkgs.length == 0 ? 1 : 0);
} else {
Deno.exit(1);
}
}
break;
default: {
const cwd = Path.cwd().join(subcommand as string);
await dump(cwd, { dryrun, quiet });
}
}
}