Skip to content

Commit 0b2eef2

Browse files
committed
fix(sim-cli): an id-shaped token lists the flags on a command with no positional
1 parent 906651b commit 0b2eef2

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎packages/sim-cli/src/embed-isolation.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,17 @@ describe('embedded CLI output ownership', () => {
8888
expect(invalid.stderr).toContain('missing required argument')
8989
})
9090

91-
it('answers a guessed flag with the command flags and an id that opens with a dash with the escape', async () => {
91+
it('answers a guessed flag with the command flags, and an id that opens with a dash with the escape', async () => {
9292
const transport = async () => {
9393
throw new Error('a parse error must not reach the API')
9494
}
95-
const [guessed, dashedId] = await Promise.all([
95+
const [guessed, dashedId, noArguments] = await Promise.all([
9696
runEmbeddedCli(['tables', 'rows', 'batch-delete', 'tbl_1', '--row-ids', 'row_1', '--yes'], {
9797
...identity,
9898
transport,
9999
}),
100100
runEmbeddedCli(['audit-logs', 'get', '-X9abc'], { ...identity, transport }),
101+
runEmbeddedCli(['logs', 'list', '-X9abc'], { ...identity, transport }),
101102
])
102103
expect(guessed.exitCode).toBe(1)
103104
expect(guessed.stderr).toContain("unknown option '--row-ids'")
@@ -106,5 +107,9 @@ describe('embedded CLI output ownership', () => {
106107
expect(dashedId.exitCode).toBe(1)
107108
expect(dashedId.stderr).toContain('Example: sim audit-logs get -- -X9abc')
108109
expect(dashedId.stderr).not.toContain('Options for')
110+
// With no positional to escape into, an id-shaped token is just an unknown option.
111+
expect(noArguments.exitCode).toBe(1)
112+
expect(noArguments.stderr).toContain('Options for sim logs list:')
113+
expect(noArguments.stderr).not.toContain('Example:')
109114
})
110115
})

‎packages/sim-cli/src/runtime/build.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ function addParseErrorGuidance(command: Command): Command {
118118

119119
const token = UNKNOWN_OPTION_TOKEN.exec(message)?.[1]
120120
if (!token) return
121-
if (looksLikeAnId(token)) {
122-
if (command.registeredArguments.length > 0)
123-
write(`Example: ${commandPath(command)} -- ${token}\n`)
121+
if (looksLikeAnId(token) && command.registeredArguments.length > 0) {
122+
write(`Example: ${commandPath(command)} -- ${token}\n`)
124123
return
125124
}
126125
const flags = command.options.filter((option) => !option.hidden).map((option) => option.flags)

0 commit comments

Comments
 (0)