scripts我package.json目前的部分看起来像这样:
"scripts": {
"start": "node ./script.js server"
}
Run Code Online (Sandbox Code Playgroud)
...这意味着我可以运行npm start来启动服务器.到现在为止还挺好.
但是,我希望能够运行类似的东西npm start 8080并将参数传递给script.js(例如npm start 8080=> node ./script.js server 8080).这可能吗?
我想创建一个Powershell脚本,它采用标准Linux风格的参数,即--my-param,带有前导 - .我认为这可能是使用alias参数属性,如
Param (
[parameter(Mandatory=$true)]
[alias("-my-param","p")]
[String]
$param
)
Run Code Online (Sandbox Code Playgroud)
我希望这是电话
c:\src\ps\params.ps1 --my-param "x"
Run Code Online (Sandbox Code Playgroud)
将被认为是指别名-my-param.不幸的是,我得到的是
C:\src\ps\params.ps1 : A positional parameter cannot be found that accepts argument 'x'.
At line:1 char:21
+ c:\src\ps\params.ps1 <<<< --my-param1 "x"
+ CategoryInfo : InvalidArgument: (:) [params.ps1], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,params.ps1
Run Code Online (Sandbox Code Playgroud)
另一方面,使用别名my-param让我用-my-param调用脚本.有没有一种方法可以使用前导Powershell指定参数名称?
这是一个非常简单的示例脚本:
function fun () { "AAA $args ZZZ" }
fun a b c
fun a - b
fun a -- b
fun a '--' b
fun a --- b
Run Code Online (Sandbox Code Playgroud)
我得到的结果是:
AAA a b c ZZZ
AAA a - b ZZZ
AAA a b ZZZ
AAA a -- ZZZ
AAA a --- b ZZZ
Run Code Online (Sandbox Code Playgroud)
我显然需要逃脱双击.为什么?
我正在为一套脚本编写一个powershell包装器,其中一些脚本为" - "赋予特定含义.我如何通过未经修改的传递?
这样做:
git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'
Run Code Online (Sandbox Code Playgroud)
正如在 Windows 机器上提到的那样,只给了我这个错误:
usage: git config [options]
Run Code Online (Sandbox Code Playgroud)
当我尝试跑步时git hist。有什么建议吗?为什么它不起作用?