45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
#!/usr/bin/env bun
|
|
|
|
import { createMain } from "citty";
|
|
import { initializeCompletion, main } from "./command/main";
|
|
import { provideContext } from "./lib/context";
|
|
import { extractConfigArgument } from "./lib/config";
|
|
import { formatUnknownError, wrapCommandErrors } from "./lib/error";
|
|
import { waitForVersionUpdate } from "./lib/version-update";
|
|
|
|
async function run() {
|
|
const { configPath, rawArgs } = extractConfigArgument(process.argv.slice(2));
|
|
// citty resolves every preceding lazy command while looking up an alias.
|
|
if (rawArgs[0] === "fuck") rawArgs[0] = "rollback";
|
|
if (
|
|
rawArgs.length === 0 ||
|
|
rawArgs[0] === "complete" ||
|
|
rawArgs[0] === "--help" ||
|
|
rawArgs[0] === "-h"
|
|
)
|
|
await initializeCompletion();
|
|
wrapCommandErrors(main);
|
|
const cli = createMain(main);
|
|
if (rawArgs[0] === "init" && configPath)
|
|
rawArgs.push("--config-path", configPath);
|
|
const contextFree = new Set([
|
|
"login",
|
|
"logout",
|
|
"whoami",
|
|
"maintenance",
|
|
"init",
|
|
]);
|
|
if (rawArgs[0] && contextFree.has(rawArgs[0])) {
|
|
await cli({ rawArgs });
|
|
return;
|
|
}
|
|
await provideContext(() => cli({ rawArgs }), configPath);
|
|
}
|
|
|
|
run()
|
|
.catch((e) => {
|
|
console.error(formatUnknownError(e));
|
|
process.exitCode = 1;
|
|
})
|
|
.finally(waitForVersionUpdate);
|