Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script argument handling can be unintuitive #1267

Open
abernardi597 opened this issue Apr 20, 2022 · 0 comments · May be fixed by #1268
Open

Script argument handling can be unintuitive #1267

abernardi597 opened this issue Apr 20, 2022 · 0 comments · May be fixed by #1268

Comments

@abernardi597
Copy link

abernardi597 commented Apr 20, 2022

Consider MyScript.sc:

@main
def doTheThing(
  @arg(short='p') parallelism: Int = 1,
  @arg dry: Flag,
  @arg ids: Leftover[Int]
) = {
  println(s"parallelism: $parallelism")
  println(s"dry: ${dry.value}")
  println(s"ids: ${ids.value.mkString("[", ", ", "]")}")
}

Currently I can invoke this like:

$ amm MyScript.sc 4 5 6 7
parallelism: 4
dry: true
ids: [6, 7]

I think it's clear how the arguments are being misconstrued. What I'd like to have is:

$ amm MyScript.sc 4 5 6 7
parallelism: 1
dry: false
ids: [4, 5, 6, 7]

As far as I can tell, this is because the main method is invoked with allowPositional = true (Scripts.scala:109).

I believe forwarding allowPositional to ammonite.Main should allow this to be configured at least in an embedded environment. Adding a command line argument shouldn't be that much more effort.

If I'm mistaken, this may end up being an improvement for mainargs instead.

I have confirmed that allowPositional = false results in the expected behavior.

@abernardi597 abernardi597 linked a pull request Apr 21, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant