This repository has been archived by the owner on Aug 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eggs.ts
122 lines (107 loc) · 2.47 KB
/
eggs.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env -S deno run -A --unstable
/// <reference no-default-lib="true" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.window" />
/// <reference lib="deno.unstable" />
// deno-lint-ignore-file
import { DenoLand, log, UpdateNotifier } from "./deps.ts";
import {
Command,
completions,
type DefaultOptions,
help,
info,
init,
install,
link,
publish,
update,
upgrade,
} from "./src/commands.ts";
import {
errorOccurred,
handleError,
setupLog,
writeLogFile,
} from "./src/utilities/log.ts";
import { version } from "./src/version.ts";
import { LogLevelNames, logLevelType } from "./src/utilities/types.ts";
const commands = {
help,
completions,
info,
init,
install,
link,
publish,
update,
upgrade,
};
await setupLog();
const notifier = new UpdateNotifier({
name: "eggs",
registry: DenoLand,
currentVersion: version,
});
const checkForUpdates = notifier.checkForUpdates();
// @ts-ignore deep types
const eggs = new Command()
.throwErrors()
.name("eggs")
.version(version)
.description(
"🥚 nest.land - module registry and CDN for Deno, on the permaweb",
)
.type("LogLevel", logLevelType, { global: true })
.option("-D, --debug", "Print additional information.", { global: true })
.option("-o, --output-log", "Create a log file after execution.", {
global: true,
})
.option("-L, --log-level <level:LogLevel>", `Set log level.\n`, {
global: true,
default: "info" as unknown as LogLevelNames,
})
.option("-q, --quiet", "Suppress diagnostic output", {
global: true,
default: false,
})
.action(() => {
eggs.showHelp();
});
export type CommandName = keyof typeof commands;
for (const name in commands) {
eggs.command(name, commands[name as CommandName]);
}
try {
const { options } = await eggs.parse(Deno.args);
if (options.outputLog) {
await writeLogFile();
}
await notification();
if (errorOccurred) {
Deno.exit(1);
}
Deno.exit();
} catch (err) {
if (
err.message.match(
/^(Unknown option:|Unknown command:|Option --|Missing value for option:|Missing argument\(s\):)/,
)
) {
const command = Deno.args[0] as keyof typeof commands;
if (command in commands) {
commands[command].showHelp();
} else {
eggs.showHelp();
}
log.error(err.message);
} else {
await handleError(err);
}
await notification();
Deno.exit(1);
}
async function notification() {
await checkForUpdates;
notifier.notify("eggs upgrade");
}