使用字符串中的参数从 Powershell 调用 hg

Calling hg from Powershell with arguments in string

我正在尝试使用 Powershell 为 Mercurial 自动化一些东西。

这一定是我如何调用 "hg.exe" 而不是 Mercurial 本身的问题,但我无法让它工作。

我想用我在 运行 时在 Powershell 中构建的一些参数执行 hg clone。到目前为止,我正在这样做:

$SourceRepo = "http://some.url.com/where.i.have.a.repo"
$TargetRepo = "d:\path\to\local\copy"
hg clone $SourceRepo $TargetRepo

问题是,http://some.url.com 需要身份验证。当 运行 运行脚本时,我要求用户输入用户名和密码。假设我将它们分别存储在 $Username$Password 中。

我可以使用 --config 将身份验证数据传递给 Mercurial。然后我像这样构建一个字符串

$hgAuth = "--config auth.x.prefix=* --config auth.x.username=$Username --config auth.x.password=$Password --config auth.x.schemes=http

所以我这样调用我的脚本:

hg clone $SourceRepo $TargetRepo $hgAuth

但是 Mercurial 因错误而中止,说:

hg : hg clone: option --config auth.x.prefix not recognized

如果我不使用这些变量,而是在 powershell 中编写相同的命令作为纯文本 运行 它,它会按预期工作。

所以我想我必须用不同的方式将参数传递给hg。我只是不知道我做错了什么。

正如上面评论中指出的,我不得不将它拆分成一个数组。

@PetSerAl:我不知道你为什么不post它作为一个答案,所以我会post它自己在这里。

像这样完成就可以了:

$hgAuth = "--config", "auth.x.prefix=*", "--config", "auth.x.username=$Username", "--config", "auth.x.password=$Password", "--config", "auth.x.schemes=http"