1

使用 ammonite,我正在尝试运行一个带有命令行参数的脚本。我只是无法弄清楚我做错了什么。它可以在具有不同版本 ammonite 的 Linux 下工作,但不能在使用自制软件的 OS X 下工作:

根据文档,这是如何做到的:

val x = 1

@main
def main(i: Int, s: String, path: os.Path = os.pwd) = {
  println("hello");
  s"Hello! ${s * i} ${path.last}."
}
println("hello 2"); 

但是,@main 注释似乎没有做任何事情:

[dmg:/tmp] % amm rip7.sc --i=3 --s='this is the' 
hello 2
Script rip7.sc does not take arguments: "--i=3" "--s=this is the"
⌁ [dmg:/tmp] 1 % amm rip7.sc 3 'this is the' 
hello 2
Script rip7.sc does not take arguments: "3" "this is the"

amm 的版本是(在 mac 上运行,使用自制软件):

[dmg:/tmp] % amm       
Loading...
Welcome to the Ammonite Repl 2.4.0 (Scala 3.0.0 Java 16.0.1)
@  

同样的程序在 linux 上运行:

% amm /tmp/rip7.sc --i 10 --s 'the end'
Compiling /tmp/rip7.sc
hello 2
hello
"Hello! the endthe endthe endthe endthe endthe endthe endthe endthe endthe end dmg."

菊石版:

% 毫米

Loading...
Compiling (synthetic)/ammonite/predef/sourceBridge.sc
Compiling (synthetic)/ammonite/predef/frontEndBridge.sc
Welcome to the Ammonite Repl 2.0.4 (Scala 2.13.1 Java 11.0.11)
4

1 回答 1

0

我只是遇到了同样的问题-似乎 brew 版本有一些问题。我 brew 卸载,然后按照scala 脚本部分中的明确说明进行操作:

sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/com-lihaoyi/Ammonite/releases/download/2.4.0/2.13-2.4.0) > /usr/local/bin/amm && chmod +x /usr/local/bin/amm' && amm

魔法!该脚本现在有效。

于 2021-08-26T14:41:14.560 回答