-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Make CLI cleanup cross-platform #3620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,18 @@ program | |
| .option('-y, --yes', 'Skip interactive prompts and use defaults') | ||
| .option('--no-pull', 'Skip pulling the latest Docker images') | ||
|
|
||
| async function runCommandQuiet(command: string[]): Promise<boolean> { | ||
| return new Promise((resolve) => { | ||
| const process = spawn(command[0], command.slice(1), { stdio: 'ignore' }) | ||
| process.on('error', () => { | ||
| resolve(false) | ||
| }) | ||
| process.on('close', (code) => { | ||
| resolve(code === 0) | ||
| }) | ||
| }) | ||
| } | ||
|
Comment on lines
+27
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then callers use Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New function duplicates existing one with minor differenceLow Severity
Additional Locations (1) |
||
|
|
||
| function isDockerRunning(): Promise<boolean> { | ||
| return new Promise((resolve) => { | ||
| const docker = spawn('docker', ['info']) | ||
|
|
@@ -66,12 +78,8 @@ async function pullImage(image: string): Promise<boolean> { | |
| } | ||
|
|
||
| async function stopAndRemoveContainer(name: string): Promise<void> { | ||
| try { | ||
| execSync(`docker stop ${name} 2>/dev/null || true`) | ||
| execSync(`docker rm ${name} 2>/dev/null || true`) | ||
| } catch (_error) { | ||
| // Ignore errors, container might not exist | ||
| } | ||
| await runCommandQuiet(['docker', 'stop', name]) | ||
| await runCommandQuiet(['docker', 'rm', name]) | ||
| } | ||
|
|
||
| async function cleanupExistingContainers(): Promise<void> { | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processNaming the spawned child
processsilently shadows Node.js's built-inprocessglobal for the rest of this function body. Any future code added inside this function that tries to callprocess.exit(),process.env, etc., will unexpectedly operate on theChildProcessobject instead. The same pattern already exists inrunCommand(line 51) — this PR replicates it. Rename both to something likeprocorchild.