【问题标题】:Ammonite: Script ... does not take arguments (under OS X)Ammonite: Script ... 不接受参数(在 OS X 下)
【发布时间】:2021-09-11 03:37:29
【问题描述】:

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

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

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)

【问题讨论】:

    标签: macos scala ammonite


    【解决方案1】:

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

    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
    

    魔法!该脚本现在可以运行了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-17
      • 2015-02-14
      • 1970-01-01
      • 2012-08-24
      • 2021-12-25
      • 2019-07-14
      相关资源
      最近更新 更多