Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/sim-cli/src/runtime/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,24 @@ describe('parse-error guidance for a value typed where a flag belongs', () => {
expect(stderr).toContain('Example: sim move <id> --workspace <id>')
})

it('points an id that opens with a dash past the option parser', () => {
expect(stderrOf(move(), ['-Ab3xYz', '--workspace', 'ws_1'])).toContain(
'Example: sim move -- -Ab3xYz'
)
})

it('treats a lowercase dash token as a misspelt flag, not an id', () => {
const stderr = stderrOf(move(), ['-abc', '--workspace', 'ws_1'])
expect(stderr).not.toContain('Example: sim move --')
expect(stderr).toContain('Options for sim move: -w, --workspace <id>')
})

it('answers a long dash token that is neither flag nor id in linear time', () => {
const started = performance.now()
stderrOf(move(), [`-${'0'.repeat(100_000)}!`, '--workspace', 'ws_1'])
expect(performance.now() - started).toBeLessThan(1000)
})

it('names no flag when two required flags are missing', () => {
const create = new Command('create')
.requiredOption('--name <value>')
Expand Down
4 changes: 1 addition & 3 deletions packages/sim-cli/src/runtime/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ function commandPath(command: Command): string {
*/
function looksLikeAnId(token: string): boolean {
return (
token.length > 2 &&
!token.startsWith('--') &&
/^-[A-Za-z0-9_-]*[A-Z0-9][A-Za-z0-9_-]*$/.test(token)
token.length > 2 && !token.startsWith('--') && /^-[\w-]+$/.test(token) && /[A-Z0-9]/.test(token)
)
}

Expand Down
Loading