We use Google's zx to write scripts.
Its feature of automatically quoting all arguments works great in most circumstances, but sometimes we run into problems. For example, we want to issue the following command in our zx script:
eas build --local --platform ios --profile development
This command, when directly executed, works great:
await $`eas build --local --platform ios --profile development`
The arguments to eas build
are dynamic, so we want to build the command:
const commandArgs = `${local ? ' --local' : ''}${platform ? ` --platform ${platform}` : ''}${profile ? ` --profile ${profile}` : ''}`;
...
await $`eas build ${command}`;
This leads to an error:
stderr: '/bin/bash: eas build --platform ios --local --profile development: command not found\n',
Second attempt was with the feature Array of Arguments:
const args = ['--local', '--profile development'];
if (platform) {
args.push(`--platform ${platform}`);
}
...
await $`eas build ${args}`;
This time, the error is:
stdout: 'Unexpected arguments: --platform ios, --profile development\n' +
Any idea?
We use Google's zx to write scripts.
Its feature of automatically quoting all arguments works great in most circumstances, but sometimes we run into problems. For example, we want to issue the following command in our zx script:
eas build --local --platform ios --profile development
This command, when directly executed, works great:
await $`eas build --local --platform ios --profile development`
The arguments to eas build
are dynamic, so we want to build the command:
const commandArgs = `${local ? ' --local' : ''}${platform ? ` --platform ${platform}` : ''}${profile ? ` --profile ${profile}` : ''}`;
...
await $`eas build ${command}`;
This leads to an error:
stderr: '/bin/bash: eas build --platform ios --local --profile development: command not found\n',
Second attempt was with the feature Array of Arguments:
const args = ['--local', '--profile development'];
if (platform) {
args.push(`--platform ${platform}`);
}
...
await $`eas build ${args}`;
This time, the error is:
stdout: 'Unexpected arguments: --platform ios, --profile development\n' +
Any idea?
Share Improve this question asked Feb 16 at 9:29 Jonas SourlierJonas Sourlier 14.4k20 gold badges84 silver badges158 bronze badges1 Answer
Reset to default 0Turns out, we need to add arguments like '--profile development'
as separate strings:
const args = ['--local', '--profile', 'development'];
if (platform) {
args.push('--platform', platform);
}
...
await $`eas build ${args}`;