Skip to content

Commit 551de95

Browse files
committed
fix(sim-setup): stop suggesting re-setup when no install is found
1 parent e219a4b commit 551de95

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

‎packages/sim-setup/src/lifecycle.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
composeServiceQuery,
99
composeServiceState,
1010
type Install,
11+
noInstallHint,
1112
serviceStatusRows,
1213
} from './lifecycle'
1314

@@ -131,3 +132,18 @@ describe('status service rows', () => {
131132
])
132133
})
133134
})
135+
136+
describe('no-install hint', () => {
137+
it('blames Docker, not the install, when Docker is unreachable', () => {
138+
const lines = noInstallHint({ dockerReachable: false, cwd: '/home/dev' })
139+
expect(lines.join(' ')).toContain('Docker is not reachable')
140+
expect(lines.join(' ')).not.toContain('npx sim-setup')
141+
})
142+
143+
it('points an existing user at the sim/ folder or --dir before suggesting setup', () => {
144+
const lines = noInstallHint({ dockerReachable: true, cwd: '/home/dev' })
145+
expect(lines[0]).toContain('/home/dev')
146+
expect(lines[1]).toContain('--dir')
147+
expect(lines[2]).toContain('npx sim-setup')
148+
})
149+
})

‎packages/sim-setup/src/lifecycle.ts‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,26 @@ function describeInstall(install: Install): string {
360360
return `Kubernetes (context ${install.context}${scope})`
361361
}
362362

363+
/**
364+
* What to say when no install was found. "Run npx sim-setup" reads as "install
365+
* again", which is wrong in the two common cases: Docker is down (a Compose
366+
* stack is invisible, not missing), or the stack was taken `down` and the
367+
* command runs outside its directory, where only `--dir` can find it.
368+
*/
369+
export function noInstallHint(options: { dockerReachable: boolean; cwd: string }): string[] {
370+
if (!options.dockerReachable) {
371+
return [
372+
'Docker is not reachable, so a Compose install cannot be detected.',
373+
'Start Docker Desktop (or OrbStack), then re-run this command.',
374+
]
375+
}
376+
return [
377+
`No Sim install found from ${options.cwd}.`,
378+
`Already set up? Run this from the folder that contains your sim/ directory, or pass ${theme.command('--dir <path-to-sim>')}.`,
379+
`New here? Run ${theme.command('npx sim-setup')}.`,
380+
]
381+
}
382+
363383
/** One install → use it; several → let the user pick; none → null. */
364384
async function resolveInstall(installs: Install[]): Promise<Install | null> {
365385
if (installs.length <= 1) return installs[0] ?? null
@@ -656,11 +676,13 @@ async function status(): Promise<void> {
656676
console.log(` ${theme.muted('start Docker Desktop (or OrbStack), then re-run this.')}\n`)
657677
}
658678
if (installs.length === 0) {
659-
console.log(
660-
docker
661-
? ` ${glyph.warn} No Sim install detected — run ${theme.command('npx sim-setup')}.`
662-
: ` ${glyph.warn} No install detected, but that may just be Docker being down.`
663-
)
679+
if (!docker) {
680+
console.log(` ${glyph.warn} No install detected, but that may just be Docker being down.`)
681+
return
682+
}
683+
const [first, ...rest] = noInstallHint({ dockerReachable: true, cwd: process.cwd() })
684+
console.log(` ${glyph.warn} ${first}`)
685+
for (const line of rest) console.log(` ${theme.muted(line)}`)
664686
return
665687
}
666688
for (const install of installs) console.log(` ${glyph.pass} ${describeInstall(install)}`)
@@ -696,7 +718,7 @@ export async function runLifecycle(command: LifecycleCommand): Promise<void> {
696718

697719
const install = await resolveInstall(installs)
698720
if (!install) {
699-
p.log.warn(`No Sim install detected. Run ${theme.command('npx sim-setup')} first.`)
721+
p.log.warn(noInstallHint({ dockerReachable: dockerReachable(), cwd: process.cwd() }).join('\n'))
700722
return
701723
}
702724
switch (command) {

0 commit comments

Comments
 (0)