49 lines
1.4 KiB
TypeScript
49 lines
1.4 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 { preflightVersion, propagateCommandExit } from "./lib/version-update";
|
|
|
|
async function run() {
|
|
const originalArgs = process.argv.slice(2);
|
|
const replay = await preflightVersion(originalArgs);
|
|
if (replay) {
|
|
propagateCommandExit(replay);
|
|
return;
|
|
}
|
|
const { configPath, rawArgs } = extractConfigArgument(originalArgs);
|
|
// 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;
|
|
});
|