Skip to content

Commit 3988223

Browse files
authored
Merge pull request #203 from deploystackio/fix/run-cmd
fix(run-command-parser): improve argument parsing for docker run commands
2 parents 089398a + dd8f479 commit 3988223

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

src/sources/run/index.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export class RunCommandParser implements SourceParser {
3131

3232
// Parse the arguments
3333
let i = 2; // Skip 'docker' and 'run'
34+
let imageFound = false;
35+
const commandParts: string[] = [];
36+
3437
while (i < parts.length) {
3538
const arg = parts[i];
3639

@@ -63,16 +66,27 @@ export class RunCommandParser implements SourceParser {
6366
break;
6467

6568
default:
66-
if (!arg.startsWith('-')) {
67-
config.image = parseDockerImage(arg);
69+
// Skip other options
70+
if (arg.startsWith('--')) {
71+
i++; // Skip the value of the option if it exists
6872
}
6973
}
70-
} else {
74+
} else if (!imageFound) {
75+
// First non-option argument is the image
7176
config.image = parseDockerImage(arg);
77+
imageFound = true;
78+
} else {
79+
// Any arguments after the image are part of the command
80+
commandParts.push(arg);
7281
}
7382

7483
i++;
7584
}
85+
86+
// Join the command parts if any were found
87+
if (commandParts.length > 0) {
88+
config.command = commandParts.join(' ');
89+
}
7690

7791
if (environmentOptions) {
7892
const serviceName = 'default'; // Docker run always uses 'default' as service name
@@ -120,8 +134,6 @@ export class RunCommandParser implements SourceParser {
120134
'default': config
121135
}
122136
};
123-
124-
125137
}
126138

127139
validate(content: string): boolean {
@@ -145,7 +157,6 @@ export class RunCommandParser implements SourceParser {
145157
for (let i = 0; i < command.length; i++) {
146158
const char = command[i];
147159

148-
149160
if (char === '\'' || char === '"') {
150161
inQuotes = !inQuotes;
151162
continue;

0 commit comments

Comments
 (0)