UNPKG

@jasondark/proompt

Version:

CLI tool for running AI prompts with structure and repeatability

100 lines 3.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupCli = exports.handleMainOptions = void 0; const commander_1 = require("commander"); const fs_1 = require("fs"); const path_1 = require("path"); const commands_1 = require("@/commands"); const shell_1 = require("@/completion/shell"); const command_utils_1 = require("@/core/command-utils"); /** * Change working directory if cwd option is provided */ const changeWorkingDirectory = (cwd) => { if (cwd) { try { process.chdir(cwd); console.log(`Changed working directory to: ${process.cwd()}`); } catch (error) { console.error(`Failed to change directory to ${cwd}: ${error.message}`); process.exit(1); } } }; /** * Handle the main CLI options (list, set-llm-cli, completion, etc.) */ const handleMainOptions = (options, complete) => { // Change working directory first if specified changeWorkingDirectory(options.cwd); if (options.completion) { return; } if (options.setupCompletion) { try { complete.setupShellInitFile(); console.log('Shell completion has been set up! Please restart your shell or run:'); console.log(' source ~/.bashrc # for bash'); console.log(' source ~/.zshrc # for zsh'); } catch (error) { console.error('Failed to setup completion:', error.message); console.log('You can manually add this to your shell config:'); console.log('eval "$(proompt --completion)"'); process.exit(1); } return; } if (options.list) { const commandModules = (0, commands_1.getCommandModules)(); console.log('Available proompts:'); for (const module of commandModules) { console.log(` ${module.config.name.padEnd(20)}${module.config.description}`); } return; } }; exports.handleMainOptions = handleMainOptions; /** * Get version from package.json */ const getVersion = () => { try { const packageJsonPath = (0, path_1.join)(__dirname, '../../package.json'); const packageJson = JSON.parse((0, fs_1.readFileSync)(packageJsonPath, 'utf8')); return packageJson.version; } catch { return '0.0.0'; } }; /** * Set up the main CLI program with all options and commands */ const setupCli = () => { const program = new commander_1.Command(); const complete = (0, shell_1.setupCompletion)(); program .name('proompt') .description('CLI tool for running AI prompts with structure and repeatability') .version(getVersion(), '-v, --version', 'display version number'); program .option('--completion', 'output completion script for shell') .option('--setup-completion', 'setup shell completion') .option('-l, --list', 'list all available proompts') .option('-C, --cwd <directory>', 'change working directory before running command') .action((options) => (0, exports.handleMainOptions)(options, complete)); // Register all command modules automatically const commandModules = (0, commands_1.getCommandModules)(); for (const commandModule of commandModules) { (0, command_utils_1.registerCommandModule)(program, commandModule); } program.on('command:*', () => { console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' ')); process.exit(1); }); return program; }; exports.setupCli = setupCli; //# sourceMappingURL=setup.js.map