diff --git a/packages/sim-cli/src/commands/protocol/workflow-dir.ts b/packages/sim-cli/src/commands/protocol/workflow-dir.ts
index 6b7f6b758ad..cdd4fccf223 100644
--- a/packages/sim-cli/src/commands/protocol/workflow-dir.ts
+++ b/packages/sim-cli/src/commands/protocol/workflow-dir.ts
@@ -126,7 +126,7 @@ export async function readBase(
const { base } = parsed
if (workflowId !== undefined && base.workflowId !== workflowId) {
throw new SourceDirError(
- `${directory} holds the source of workflow ${base.workflowId}, not ${workflowId}. Apply it to ${base.workflowId}, or write this workflow's source with \`sim workflows source get ${workflowId} --dir
\`.`,
+ `${directory} holds the source of workflow ${base.workflowId}, not ${workflowId}. Apply it to ${base.workflowId}, or write this workflow's source with \`sim workflows source get ${shellWord(workflowId)} --dir \`.`,
{ code: 'SOURCE_WORKFLOW_MISMATCH' }
)
}
@@ -153,7 +153,7 @@ export async function readLock(directory: string): Promise {
const parsed = parseWorkflowLock(await readJson(directory, SOURCE_LOCK_FILE, GET_HINT))
if (parsed.lock) return parsed.lock
throw new SourceDirError(
- `${SOURCE_LOCK_FILE} in ${directory} is not a valid lock: ${parsed.diagnostics.map(lockProblem).join('; ')}. ${lockRecoveryHint()}`
+ `${SOURCE_LOCK_FILE} in ${directory} is not a valid lock: ${parsed.diagnostics.map(lockProblem).join('; ')} ${lockRecoveryHint()}`
)
}
diff --git a/packages/sim-cli/src/commands/protocol/workflow-source-find.ts b/packages/sim-cli/src/commands/protocol/workflow-source-find.ts
index 1ad87bdbbdf..d0b9b9a8405 100644
--- a/packages/sim-cli/src/commands/protocol/workflow-source-find.ts
+++ b/packages/sim-cli/src/commands/protocol/workflow-source-find.ts
@@ -306,7 +306,7 @@ function printNumbered(lines: readonly string[], first: number, indent: string):
lines.forEach((text, at) => printLine(`${indent}${String(first + at).padStart(width)} ${text}`))
}
-function printFound(found: FoundBlock): void {
+function printFound(found: FoundBlock, compiles: boolean): void {
const kind = found.type ? `${found.type}, ` : ''
printLine(`${found.name} (${kind}key ${found.key}, ${found.ident})`)
if (found.declaration !== '') printNumbered(found.declaration.split('\n'), found.line, '')
@@ -319,6 +319,10 @@ function printFound(found: FoundBlock): void {
const edgeRow = (edge: FoundEdge) => `${edge.file}:${edge.line} ${edge.statement}`
section('in', found.incoming.map(edgeRow))
section('out', found.outgoing.map(edgeRow))
+ if (!compiles) {
+ printLine('read by: unknown (the source does not compile)')
+ return
+ }
section(
'read by',
found.readers.map(
@@ -379,7 +383,7 @@ export function attachWorkflowSourceFind(source: Command): void {
}
found.forEach((block, position) => {
if (position > 0) printLine('')
- printFound(block)
+ printFound(block, compiled.workflow !== null)
})
if (more > 0) printLine(`\n${more} more blocks match; name one exactly to print it.`)
}
diff --git a/packages/sim-cli/src/commands/protocol/workflow-source-roundtrip.test.ts b/packages/sim-cli/src/commands/protocol/workflow-source-roundtrip.test.ts
index fdc59ca49a8..5641b7142b0 100644
--- a/packages/sim-cli/src/commands/protocol/workflow-source-roundtrip.test.ts
+++ b/packages/sim-cli/src/commands/protocol/workflow-source-roundtrip.test.ts
@@ -1,3 +1,4 @@
+import { execFileSync } from 'node:child_process'
import {
existsSync,
mkdirSync,
@@ -325,6 +326,25 @@ describe('sim workflows source get --dir → apply --dir', () => {
expect(JSON.parse(read('.sim/base.json'))).toEqual(baseFor(NEW_WORKFLOW_ID, SECOND))
await expect(apply()).rejects.toThrow(`holds the source of workflow ${NEW_WORKFLOW_ID}`)
})
+ it('names the typed workflow as one shell word in the recovery command for a mismatched apply', async () => {
+ await get()
+
+ const error = await sim(
+ 'workflows',
+ 'source',
+ 'apply',
+ 'Lead Router',
+ '--dir',
+ dir,
+ '--yes'
+ ).catch((caught: unknown) => caught)
+
+ expect(error).toBeInstanceOf(Error)
+ const typed = /`sim workflows source get (.+) --dir `/.exec((error as Error).message)?.[1]
+ expect(typed).toBeDefined()
+ const words = execFileSync('sh', ['-c', `printf '%s\\n' ${typed}`], { encoding: 'utf8' })
+ expect(words.split('\n').filter(Boolean)).toEqual(['Lead Router'])
+ })
})
describe('the source directory never reaches outside --dir', () => {
diff --git a/packages/sim-cli/src/runtime/build.ts b/packages/sim-cli/src/runtime/build.ts
index fc303b56c2f..d385ec9cd93 100644
--- a/packages/sim-cli/src/runtime/build.ts
+++ b/packages/sim-cli/src/runtime/build.ts
@@ -63,7 +63,7 @@ function argumentSyntax(command: Command): string {
.join(' ')
}
-function commandPath(command: Command): string {
+function commandLabel(command: Command): string {
const names: string[] = []
let current: Command | null = command
while (current) {
@@ -134,7 +134,7 @@ function longFlagSyntax(option: Option): string {
/** The command line with its positionals and every required flag, as `--help` would read it. */
function usageExample(command: Command): string {
- const parts = [commandPath(command), argumentSyntax(command)]
+ const parts = [commandLabel(command), argumentSyntax(command)]
for (const option of command.options) if (option.mandatory) parts.push(longFlagSyntax(option))
return parts.filter(Boolean).join(' ')
}
@@ -142,8 +142,8 @@ function usageExample(command: Command): string {
function optionList(command: Command): string {
const flags = command.options.filter((option) => !option.hidden).map((option) => option.flags)
return flags.length > 0
- ? `Options for ${commandPath(command)}: ${flags.join(', ')}`
- : `${commandPath(command)} takes no options.`
+ ? `Options for ${commandLabel(command)}: ${flags.join(', ')}`
+ : `${commandLabel(command)} takes no options.`
}
/** What each guided command's own option parse left unknown, recorded by {@link addParseErrorGuidance}. */
@@ -181,7 +181,7 @@ function unknownBesideMissing(command: Command): string | undefined {
const typed = token.split('=', 1)[0]
const missing = missingMandatory(command).flatMap((option) => (option.long ? [option.long] : []))
const suggestion = didYouMean(typed, missing)
- return `${typed} is not an option of ${commandPath(command)}.${suggestion ? ` (${suggestion})` : ''}`
+ return `${typed} is not an option of ${commandLabel(command)}.${suggestion ? ` (${suggestion})` : ''}`
}
/**
@@ -308,7 +308,7 @@ function siblingsDeclaring(command: Command, flag: string): string[] {
.filter((candidate) =>
candidate.options.some((option) => option.long === flag || option.short === flag)
)
- .map((owner) => ` ${commandPath(owner)} — ${owner.description().split('\n', 1)[0]}`)
+ .map((owner) => ` ${commandLabel(owner)} — ${owner.description().split('\n', 1)[0]}`)
}
/**
@@ -358,7 +358,7 @@ function parseErrorGuidance(command: Command, code: string | undefined): string[
const token = unknownOptionToken(command)
if (!token) return []
if (looksLikeAnId(token) && command.registeredArguments.length > 0) {
- return [`Example: ${commandPath(command)} -- ${token}`]
+ return [`Example: ${commandLabel(command)} -- ${token}`]
}
const flag = token.split('=', 1)[0]
if (flag === '--json') return [optionList(command), 'For JSON output, pass --output json.']
diff --git a/packages/sim-cli/src/runtime/derive.ts b/packages/sim-cli/src/runtime/derive.ts
index 5ce39c5d9c6..6f59d55b318 100644
--- a/packages/sim-cli/src/runtime/derive.ts
+++ b/packages/sim-cli/src/runtime/derive.ts
@@ -26,8 +26,8 @@ const ACTION_SEGMENTS = new Set([
* Derives a command path from an operation's route.
*
* ` [sub-resource] `, where the verb comes from the method and
- * whether the path ends in a parameter (an item) or not (a collection). This
- * covers 41 of the 47 operations; the rest are named in the CLI contract.
+ * whether the path ends in a parameter (an item) or not (a collection).
+ * Covers most operations; the contract names the rest (`command`).
*/
export function deriveCommandPath(operation: V2OperationName): string[] {
const spec = V2_OPERATIONS[operation]