1

Using ammonite, I am trying to run a script that takes command line arguments. I just can't figure out what I am doing wrong. It works under Linux with a different version of ammonite, but not under OS X using homebrew:

According to the documentation this is how to do it:

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"); 

however, the @main annotation does not seem to do anything:

[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"

The version of amm is (running on mac, using homebrew):

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

This same program runs on 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."

ammonite version:

% amm

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)
dmg
  • 4,231
  • 1
  • 18
  • 24

1 Answers1

1

I just had the same issue - seems like the brew version has some issues. I brew uninstalled, then followed the explicit instructions in the 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

Magic! The script works now.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Barbara
  • 11
  • 1