[READ-ONLY] Mirror of https://github.com/bombshell-dev/tab. shell autocompletions for javascript CLIs
4

Configure Feed

Select the types of activity you want to include in your feed.

fix: validating args (#25)

* fix espace args

* update

* prettier

* update

* prettier

* throw error

* update

authored by

AmirHossein Sakhravi and committed by
GitHub
(Apr 29, 2025, 4:13 PM +0330) 6c42c55f d6372ae4

+21 -4
+4 -2
src/cac.ts
··· 4 4 import * as powershell from './powershell'; 5 5 import type { CAC } from 'cac'; 6 6 import { Completion } from './index'; 7 - import { CompletionConfig, noopHandler } from './shared'; 7 + import { CompletionConfig, noopHandler, assertDoubleDashes } from './shared'; 8 8 9 9 const execPath = process.execPath; 10 10 const processArgs = process.argv.slice(1); ··· 85 85 break; 86 86 } 87 87 default: { 88 - const args: string[] = extra['--']; 88 + assertDoubleDashes(instance.name); 89 + 90 + const args: string[] = extra['--'] || []; 89 91 instance.showHelpOnExit = false; 90 92 91 93 // Parse current command context
+4 -2
src/citty.ts
··· 11 11 SubCommandsDef, 12 12 } from 'citty'; 13 13 import { generateFigSpec } from './fig'; 14 - import { CompletionConfig, noopHandler } from './shared'; 14 + import { CompletionConfig, noopHandler, assertDoubleDashes } from './shared'; 15 15 16 16 function quoteIfNeeded(path: string) { 17 17 return path.includes(' ') ? `'${path}'` : path; ··· 155 155 }, 156 156 async run(ctx) { 157 157 let shell: string | undefined = ctx.rawArgs[0]; 158 - const extra = ctx.rawArgs.slice(ctx.rawArgs.indexOf('--') + 1); 159 158 160 159 if (shell === '--') { 161 160 shell = undefined; ··· 188 187 break; 189 188 } 190 189 default: { 190 + assertDoubleDashes(name); 191 + 192 + const extra = ctx.rawArgs.slice(ctx.rawArgs.indexOf('--') + 1); 191 193 // const args = (await resolve(instance.args))!; 192 194 // const parsed = parseArgs(extra, args); 193 195 // TODO: this is not ideal at all
+3
src/commander.ts
··· 4 4 import * as powershell from './powershell'; 5 5 import type { Command as CommanderCommand } from 'commander'; 6 6 import { Completion } from './'; 7 + import { assertDoubleDashes } from './shared'; 7 8 8 9 const execPath = process.execPath; 9 10 const processArgs = process.argv.slice(1); ··· 79 80 break; 80 81 } 81 82 default: { 83 + assertDoubleDashes(programName); 84 + 82 85 // Parse current command context for autocompletion 83 86 return completion.parse(extra); 84 87 }
+10
src/shared.ts
··· 16 16 } 17 17 >; 18 18 } 19 + 20 + export function assertDoubleDashes(programName: string = 'cli'): void { 21 + const dashDashIndex = process.argv.indexOf('--'); 22 + 23 + if (dashDashIndex === -1) { 24 + const errorMessage = `Error: You need to use -- to separate completion arguments.\nExample: ${programName} complete -- <args>`; 25 + console.error(errorMessage); 26 + process.exit(1); 27 + } 28 + }