feat(core): add root level forwardAllArgs (#22753)
This commit is contained in:
parent
55a933855c
commit
c3a3d1b0a6
@ -121,6 +121,11 @@
|
|||||||
"items": { "type": "string" },
|
"items": { "type": "string" },
|
||||||
"$default": { "$source": "unparsed" },
|
"$default": { "$source": "unparsed" },
|
||||||
"x-priority": "internal"
|
"x-priority": "internal"
|
||||||
|
},
|
||||||
|
"forwardAllArgs": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Whether arguments should be forwarded when interpolation is not present.",
|
||||||
|
"default": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": true,
|
"additionalProperties": true,
|
||||||
|
|||||||
@ -37,19 +37,61 @@ describe('Run Commands', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not pass --args into underlying command', async () => {
|
it('should not pass --args into underlying command', async () => {
|
||||||
const f = fileSync().name;
|
|
||||||
const result = await runCommands(
|
const result = await runCommands(
|
||||||
{
|
{
|
||||||
command: `echo`,
|
command: `echo`,
|
||||||
__unparsed__: ['--args=--key=123'],
|
__unparsed__: ['--args=--key=123'],
|
||||||
args: '--key=123',
|
args: '--key=123',
|
||||||
unparsedCommandArgs: { args: '--key=123' },
|
|
||||||
},
|
},
|
||||||
context
|
context
|
||||||
);
|
);
|
||||||
expect(result.terminalOutput.trim()).not.toContain('--args=--key=123');
|
expect(result.terminalOutput.trim()).not.toContain('--args=--key=123');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not foward any args to underlying command if forwardAllArgs is false', async () => {
|
||||||
|
let result = await runCommands(
|
||||||
|
{
|
||||||
|
command: `echo`,
|
||||||
|
key: 123,
|
||||||
|
__unparsed__: [],
|
||||||
|
forwardAllArgs: false,
|
||||||
|
},
|
||||||
|
context
|
||||||
|
);
|
||||||
|
expect(result.terminalOutput.trim()).not.toContain('--key=123');
|
||||||
|
|
||||||
|
result = await runCommands(
|
||||||
|
{
|
||||||
|
command: `echo`,
|
||||||
|
key: 123,
|
||||||
|
__unparsed__: [],
|
||||||
|
forwardAllArgs: true,
|
||||||
|
},
|
||||||
|
context
|
||||||
|
);
|
||||||
|
expect(result.terminalOutput.trim()).toContain('--key=123');
|
||||||
|
|
||||||
|
result = await runCommands(
|
||||||
|
{
|
||||||
|
commands: [
|
||||||
|
{
|
||||||
|
command: `echo 1`,
|
||||||
|
forwardAllArgs: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
command: `echo 2`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
__unparsed__: ['--args=--key=123'],
|
||||||
|
args: '--key=123',
|
||||||
|
forwardAllArgs: false,
|
||||||
|
},
|
||||||
|
context
|
||||||
|
);
|
||||||
|
expect(result.terminalOutput).toContain('1 --key=123');
|
||||||
|
expect(result.terminalOutput).not.toContain('2 --key=123');
|
||||||
|
});
|
||||||
|
|
||||||
it('should interpolate all unknown args as if they were --args', async () => {
|
it('should interpolate all unknown args as if they were --args', async () => {
|
||||||
const f = fileSync().name;
|
const f = fileSync().name;
|
||||||
const result = await runCommands(
|
const result = await runCommands(
|
||||||
|
|||||||
@ -54,6 +54,7 @@ export interface RunCommandsOptions extends Json {
|
|||||||
readyWhen?: string;
|
readyWhen?: string;
|
||||||
cwd?: string;
|
cwd?: string;
|
||||||
env?: Record<string, string>;
|
env?: Record<string, string>;
|
||||||
|
forwardAllArgs?: boolean; // default is true
|
||||||
args?: string | string[];
|
args?: string | string[];
|
||||||
envFile?: string;
|
envFile?: string;
|
||||||
__unparsed__: string[];
|
__unparsed__: string[];
|
||||||
@ -75,6 +76,7 @@ const propKeys = [
|
|||||||
'usePty',
|
'usePty',
|
||||||
'streamOutput',
|
'streamOutput',
|
||||||
'verbose',
|
'verbose',
|
||||||
|
'forwardAllArgs',
|
||||||
];
|
];
|
||||||
|
|
||||||
export interface NormalizedRunCommandsOptions extends RunCommandsOptions {
|
export interface NormalizedRunCommandsOptions extends RunCommandsOptions {
|
||||||
@ -244,7 +246,7 @@ function normalizeOptions(
|
|||||||
c.command = interpolateArgsIntoCommand(
|
c.command = interpolateArgsIntoCommand(
|
||||||
c.command,
|
c.command,
|
||||||
options as NormalizedRunCommandsOptions,
|
options as NormalizedRunCommandsOptions,
|
||||||
c.forwardAllArgs ?? true
|
c.forwardAllArgs ?? options.forwardAllArgs ?? true
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return options as NormalizedRunCommandsOptions;
|
return options as NormalizedRunCommandsOptions;
|
||||||
|
|||||||
@ -135,6 +135,11 @@
|
|||||||
"$source": "unparsed"
|
"$source": "unparsed"
|
||||||
},
|
},
|
||||||
"x-priority": "internal"
|
"x-priority": "internal"
|
||||||
|
},
|
||||||
|
"forwardAllArgs": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Whether arguments should be forwarded when interpolation is not present.",
|
||||||
|
"default": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": true,
|
"additionalProperties": true,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user