intent-cli
Version:
A fully functional CLI built with TypeScript and modern tools
112 lines • 4.91 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.program = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const update_notifier_1 = __importDefault(require("update-notifier"));
const logger_1 = require("./utils/logger");
const config_1 = require("./utils/config");
const hello_1 = require("./commands/hello");
const config_2 = require("./commands/config");
const init_1 = require("./commands/init");
const file_1 = require("./commands/file");
const sysinfo_1 = require("./commands/sysinfo");
const productivity_1 = require("./commands/productivity");
const interactive_simple_1 = require("./commands/interactive-simple");
const packageJson = require('../package.json');
// Check for updates
const notifier = (0, update_notifier_1.default)({
pkg: packageJson,
updateCheckInterval: 1000 * 60 * 60 * 24, // Check daily
});
if (notifier.update) {
const updateMessage = [
chalk_1.default.yellow.bold('Update available!'),
`${chalk_1.default.dim(packageJson.version)} → ${chalk_1.default.green(notifier.update.latest)}`,
chalk_1.default.dim(`Run "npm i -g ${packageJson.name}" to update`),
].join(' ');
console.log(`\n${updateMessage}\n`);
}
// Set up logging level based on config
const configValidation = config_1.config.validate();
if (!configValidation.isValid) {
console.error(chalk_1.default.red('Configuration validation failed:'));
configValidation.errors.forEach(error => {
console.error(chalk_1.default.red(` - ${error}`));
});
process.exit(1);
}
const program = new commander_1.Command();
exports.program = program;
program
.name('intent-cli')
.description('A fully functional CLI built with TypeScript and modern tools')
.version(packageJson.version, '-v, --version', 'Display version number')
.helpOption('-h, --help', 'Display help for command');
// Global options
program
.option('-v, --verbose', 'Enable verbose logging', false)
.option('-c, --config <path>', 'Path to configuration file')
.option('-o, --output <format>', 'Output format (json, table, yaml)', 'table')
.hook('preAction', (thisCommand) => {
const options = thisCommand.opts();
if (options.verbose) {
logger_1.logger.setLevel('debug');
}
if (options.config) {
logger_1.logger.debug(`Using custom config path: ${options.config}`);
}
logger_1.logger.debug(`Command: ${thisCommand.name()}`);
logger_1.logger.debug(`Options: ${JSON.stringify(options)}`);
});
// Handle uncaught exceptions
process.on('uncaughtException', (error) => {
logger_1.logger.error('Uncaught exception:', error);
process.exit(1);
});
process.on('unhandledRejection', (reason, promise) => {
logger_1.logger.error('Unhandled rejection at:', promise, 'reason:', reason);
process.exit(1);
});
// Handle SIGINT (Ctrl+C)
process.on('SIGINT', () => {
console.log('\n\nReceived SIGINT. Gracefully shutting down...');
process.exit(0);
});
// Add commands
program.addCommand(hello_1.helloCommand);
program.addCommand(config_2.configCommand);
program.addCommand(init_1.initCommand);
program.addCommand(file_1.fileCommand);
program.addCommand(sysinfo_1.sysinfoCommand);
program.addCommand(productivity_1.productivityCommand);
program.addCommand(interactive_simple_1.interactiveCommand);
// Default action if no command provided
if (process.argv.length <= 2) {
console.log(chalk_1.default.cyan.bold('🚀 Welcome to Intent CLI!'));
console.log('');
console.log('Usage:');
console.log(` ${chalk_1.default.green('intent-cli <command>')} [options]`);
console.log('');
console.log('Available commands:');
console.log(` ${chalk_1.default.green('hello')} Say hello to Intent CLI`);
console.log(` ${chalk_1.default.green('config')} Manage configuration`);
console.log(` ${chalk_1.default.green('init')} Initialize a new project`);
console.log(` ${chalk_1.default.green('file')} File management utilities`);
console.log(` ${chalk_1.default.green('sysinfo')} System information & monitoring`);
console.log(` ${chalk_1.default.green('productivity')} Productivity tools (timer, calculator, notes)`);
console.log(` ${chalk_1.default.green('interactive')} 🚀 Interactive terminal interface`);
console.log('');
console.log('Get help:');
console.log(` ${chalk_1.default.green('intent-cli --help')} Show general help`);
console.log(` ${chalk_1.default.green('intent-cli <command> --help')} Show command-specific help`);
console.log('');
process.exit(0);
}
// Parse command line arguments
program.parse();
//# sourceMappingURL=index.js.map