Skip to content

Script argument handling can be unintuitive #1267

@abernardi597

Description

@abernardi597

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions