From dd8f4796eeb41f061584f8f1aed01da9148216c1 Mon Sep 17 00:00:00 2001 From: Lasim Date: Fri, 11 Apr 2025 07:28:30 +0200 Subject: [PATCH] fix(run-command-parser): improve argument parsing for docker run commands --- src/sources/run/index.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/sources/run/index.ts b/src/sources/run/index.ts index 283b41f..18e0d45 100644 --- a/src/sources/run/index.ts +++ b/src/sources/run/index.ts @@ -31,6 +31,9 @@ export class RunCommandParser implements SourceParser { // Parse the arguments let i = 2; // Skip 'docker' and 'run' + let imageFound = false; + const commandParts: string[] = []; + while (i < parts.length) { const arg = parts[i]; @@ -63,16 +66,27 @@ export class RunCommandParser implements SourceParser { break; default: - if (!arg.startsWith('-')) { - config.image = parseDockerImage(arg); + // Skip other options + if (arg.startsWith('--')) { + i++; // Skip the value of the option if it exists } } - } else { + } else if (!imageFound) { + // First non-option argument is the image config.image = parseDockerImage(arg); + imageFound = true; + } else { + // Any arguments after the image are part of the command + commandParts.push(arg); } i++; } + + // Join the command parts if any were found + if (commandParts.length > 0) { + config.command = commandParts.join(' '); + } if (environmentOptions) { const serviceName = 'default'; // Docker run always uses 'default' as service name @@ -120,8 +134,6 @@ export class RunCommandParser implements SourceParser { 'default': config } }; - - } validate(content: string): boolean { @@ -145,7 +157,6 @@ export class RunCommandParser implements SourceParser { for (let i = 0; i < command.length; i++) { const char = command[i]; - if (char === '\'' || char === '"') { inQuotes = !inQuotes; continue;