Files
Zero/packages/cli/src/cli.ts
Mustafa Zahid 59780ef53e fix: undefined name on specific platforms fixed (#1796)
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2025-07-22 15:01:26 -07:00

51 lines
1.2 KiB
TypeScript

import { intro, select, isCancel, outro, log } from '@clack/prompts';
import * as commands from './commands';
let args = [];
if (process.argv.slice(2).length === 0) {
intro(`Welcome to the Nizzy CLI`);
const user = process.env.USER || process.env.USERNAME || 'there';
const command = await select({
message: `Hey ${user}, what do you want to do?`,
options: Object.values(commands).map((command) => ({
label: command.description,
value: command.id,
})),
maxItems: 5,
});
if (isCancel(command)) {
outro('No worries, come back anytime!');
process.exit(0);
}
args = [command];
} else {
intro(`Nizzy CLI`);
args = process.argv.slice(2);
}
if (['help', '-h', '--help'].includes(args[0])) {
log.message('Available commands:');
log.message(
Object.values(commands)
.map((command) => ` ${command.id.padStart(15)} ${command.description}`)
.join('\n'),
);
outro('Run `pnpm nizzy` for an interactive experience\n');
process.exit(0);
}
const command = Object.values(commands).find((command) => command.id === args[0]);
if (!command) {
outro("Umm, I don't know how to do that yet");
process.exit(0);
}
await command.run();
outro(`Done!`);
process.exit(0);