最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

google zx - How to dynamically build zx arguments? - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Turns 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}`;
发布评论

评论列表(0)

  1. 暂无评论