相关疑难解决方法(0)

将命令行参数发送到npm脚本

scriptspackage.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).这可能吗?

javascript node.js npm

691
推荐指数
12
解决办法
38万
查看次数

如何在PowerShell脚本中提供Linux样式的参数名称

我想创建一个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指定参数名称?

powershell

5
推荐指数
1
解决办法
552
查看次数

Powershell:为什么我需要在$ args中转义双破折号参数?

这是一个非常简单的示例脚本:

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包装器,其中一些脚本为" - "赋予特定含义.我如何通过未经修改的传递?

powershell command-line

4
推荐指数
1
解决办法
3006
查看次数

在 Windows 上通过别名将 git hist 设置为漂亮的打印日志

这样做:

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。有什么建议吗?为什么它不起作用?

windows git powershell

3
推荐指数
1
解决办法
2095
查看次数

标签 统计

powershell ×3

command-line ×1

git ×1

javascript ×1

node.js ×1

npm ×1

windows ×1