lifetracker/apps/cli/src/index.ts

47 lines
1.1 KiB
TypeScript

import { setGlobalOptions } from "@/lib/globals";
import { Command, Option } from "@commander-js/extra-typings";
import { whoamiCmd } from "@/commands/whoami";
import { colorsCmd } from "@/commands/colors";
import { config } from "dotenv";
config({
path: "./.env.local",
}
)
const program = new Command()
.name("lifetracker")
.description("A CLI interface to interact with my lifetracker api")
.addOption(
new Option("--api-key <key>", "the API key to interact with the API")
.makeOptionMandatory(true)
.env("LIFETRACKER_API_KEY"),
)
.addOption(
new Option(
"--server-addr <addr>",
"the address of the server to connect to",
)
.makeOptionMandatory(true)
.env("LIFETRACKER_SERVER_ADDR"),
)
.addOption(new Option("--json", "to output the result as JSON"))
.version(
import.meta.env && "CLI_VERSION" in import.meta.env
? import.meta.env.CLI_VERSION
: "0.0.0",
);
program.addCommand(whoamiCmd, {
isDefault: true
});
program.addCommand(colorsCmd);
setGlobalOptions(program.opts());
program.parse();