Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/bombshell-dev/tab. shell autocompletions for javascript CLIs
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167import { Command, Option } from 'commander';import tab from '../src/commander';
// Create a new Commander programconst program = new Command('myapp');program.version('1.0.0');
// Add global optionsprogram .option('-c, --config <file>', 'Use specified config file') .option('-m, --mode <mode>', 'Set env mode') .addOption( new Option('-l, --logLevel <level>', 'Specify log level').choices([ 'info', 'warn', 'error', 'silent', ]) );
// Add commandsconst devCommand = program .command('dev') .description('Start dev server') .option('-H, --host [host]', `Specify hostname`) .option('-p, --port <port>', `Specify port`) .option('-v, --verbose', `Enable verbose logging`) .option('--quiet', `Suppress output`) .action((options) => {});// subcommands of devdevCommand .command('start') .description('Start development server') .action((options) => {});devCommand .command('build') .description('Build project') .action((options) => {});
program .command('serve') .description('Start the server') .option('-p, --port <number>', 'port to use', '3000') .option('-H, --host <host>', 'host to use', 'localhost') .action((options) => { console.log('Starting server...'); });
program .command('build') .description('Build the project') .option('-m, --mode <mode>', 'build mode', 'production') .option('--no-minify', 'disable minification') .action((options) => { console.log('Building project...'); });
// Command with subcommandsconst deploy = program.command('deploy').description('Deploy the application');
deploy .command('staging') .description('Deploy to staging environment') .action(() => { console.log('Deploying to staging...'); });
deploy .command('production') .description('Deploy to production environment') .action(() => { console.log('Deploying to production...'); });
// Command with positional argumentsprogram .command('lint [files...]') .description('Lint source files') .option('--fix', 'automatically fix problems') .action((files, options) => { console.log('Linting files...'); });
// Command with multiple required positional argumentsprogram .command('copy <source> <destination>') .description('Copy files') .action((source, destination) => { console.log(`Copying ${source} to ${destination}...`); });
// Initialize tab completionconst completion = tab(program);
// Configure custom completions// Options on root commandconst configOption = completion.options.get('config');if (configOption) { configOption.handler = (complete) => { complete('vite.config.ts', 'Vite config file'); complete('vite.config.js', 'Vite config file'); };}const modeOption = completion.options.get('mode');if (modeOption) { modeOption.handler = (complete) => { complete('development', 'Development mode'); complete('production', 'Production mode'); };}// Note: loglevel automatically gets completions because uses ".choices()" in option definition.
// Options on dev commandconst devCommandInstance = completion.commands.get('dev');if (devCommandInstance) { const portOption = devCommandInstance.options.get('port'); if (portOption) { portOption.handler = (complete) => { complete('3000', 'Development server port'); complete('8080', 'Alternative port'); }; } const hostOption = devCommandInstance.options.get('host'); if (hostOption) { hostOption.handler = (complete) => { complete('localhost', 'Localhost'); complete('127.0.0.1', 'Localhost IP'); }; }}
// Positional arguments on lint commandconst lintCommandInstance = completion.commands.get('lint');if (lintCommandInstance) { const filesArg = lintCommandInstance.arguments.get('files'); if (filesArg) { filesArg.handler = (complete) => { complete('main.ts', 'Main file'); complete('index.ts', 'Index file'); }; }}
// Positional arguments on copy commandconst copyCommandInstance = completion.commands.get('copy');if (copyCommandInstance) { const sourceArg = copyCommandInstance.arguments.get('source'); if (sourceArg) { sourceArg.handler = (complete) => { complete('src/', 'Source directory'); complete('dist/', 'Distribution directory'); complete('public/', 'Public assets'); }; } const destinationArg = copyCommandInstance.arguments.get('destination'); if (destinationArg) { destinationArg.handler = (complete) => { complete('build/', 'Build output'); complete('release/', 'Release directory'); complete('backup/', 'Backup location'); }; }}
// Parse command line argumentsprogram.parse();