如何将命令行参数传递给嵌套脚本? [英] How to pass a command line argument to a nested script?
问题描述
注意:这不是关于将args发送到顶级脚本,而是发送到 b 在我的package.json中,当我调用一个直接接受命令行args的脚本时,它可以工作。但是当我调用一个调用其他脚本的脚本时,它并没有将命令行args传递给它。我如何通过它们? 当我运行以下命令时,args通过: 但是当我通过其他脚本运行它时,它永远不会得到args。有没有办法让他们失望?也许通过像美元符号这样的变量标记? 有没有办法? 您的 注意 在 如果你将 如果你没有将任何args传递给 编辑: 如果你不能/不想修改你的 那将运行 NOTE: This is NOT about sending args to the top-level script, but to the script called by that script In my package.json, when I call a script that takes command line args directly, it works. But when I call a script that calls that other script, it's not passing the command line args to it. How do i pass them? When i run the below command, the args come through: But when I run it through the other script, it never gets the args. Is there some way to pass them down? Maybe by a variable marker like a dollar sign? Is there any way? Your Notice the Anything you pass after the If you add the If you don't pass any args to Edit: If you can't/don't want to modify your That will run 这篇关于如何将命令行参数传递给嵌套脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
{
...
takes-args:somemodule ,
calls-takes-args:npm run takes-args
}
npm run takes-args - -env dev
//顶级脚本获取args,BUT take-args NOT
npm run calls-takes-args - -env dev
脚本
字段应如下所示:
{
...
take-args:somemodule,
来电 - take-args:npm run takes-args -
}
-
在 call-takes-args
结束时。
-
之后传递的任何内容都会直接附加到您正在运行的脚本上。当你运行 npm run calls-takes-args - -env dev
时,这相当于运行 npm run takes-args -env dev
。当然,这不起作用。
-
添加到来电-takes-args
,当你运行 npm run calls-takes-args - -env dev
, npm run
运行 npm run takes-args - -env dev
。成功!
calls-takes-args
,则尾随 -
不会受到伤害。
package.json
,你可以运行
npm run calls-takes-args - - -env dev
somemodule -env dev
。{
...
"takes-args": "somemodule",
"calls-takes-args": "npm run takes-args"
}
npm run takes-args -- -env dev
//The top-level script gets the args, BUT takes-args does NOT
npm run calls-takes-args -- -env dev
scripts
field should look like this:{
...
"takes-args": "somemodule",
"calls-takes-args": "npm run takes-args --"
}
--
at the end of calls-takes-args
.--
is directly appended onto the script you are running. When you run npm run calls-takes-args -- -env dev
, that is the equivalent of running npm run takes-args -env dev
. Of course, that does not work.--
to calls-takes-args
, when you run npm run calls-takes-args -- -env dev
, npm run
runs npm run takes-args -- -env dev
. Success!calls-takes-args
, the trailing --
won't hurt.
package.json
, you can run npm run calls-takes-args -- -- -env dev
somemodule -env dev
.