-
Notifications
You must be signed in to change notification settings - Fork 128
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
Scripting: access to command line arguments #157
Comments
doesn't work yet, blocked by VirtusLab/scala-cli#157
Not sure about ➜ cat A.scala
@main def f(s: String) = println(s"Hello $s")
➜ scala-cli A.scala -- World
Hello World |
fwiw, Ammonite also requires defining a @lrytz reports that defining a my expectation that an explicit main method shouldn't be necessary comes from three places:
|
and it turns out I'm not actually able to use I have: #!/usr/bin/env scala-cli --scala-version 3.1.0-RC2
import $dep.`org.scala-lang.modules:scala-parallel-collections_3:1.0.3`
import scala.collection.parallel.CollectionConverters._ // for .par but I get:
|
Now it is poosible to run ``` echo "println(args)" > a.sc && scala-cli run ./a.sc -- foo bar ``` closes VirtusLab#157
Now it is poosible to run ``` echo "println(args)" > a.sc && scala-cli run ./a.sc -- foo bar ``` closes VirtusLab#157
Now it is poosible to run ``` echo "println(args)" > a.sc && scala-cli run ./a.sc -- foo bar ``` closes VirtusLab#157
Now it is poosible to run ``` echo "println(args)" > a.sc && scala-cli run ./a.sc -- foo bar ``` closes VirtusLab#157
Now it is poosible to run ``` echo "println(args)" > a.sc && scala-cli run ./a.sc -- foo bar ``` closes VirtusLab#157
@tpasternak I'm having trouble combining this with also passing flags to scala-cli for example, suppose I want to pass I tried:
and it aaaaaaalmost works right. I can do:
and I can do:
but note that I had to supply the extra
happy to open a new ticket on this if you'd prefer. |
Thank you @SethTisue , you're right, I'm reopening the issue |
@SethTisue We are thinking about how to improve the situation and to be honest I cannot see how we can get rid of Any ideas on how to improve the situation? I do not see any other option than just updating documentation. |
I haven't thought about this deeply, but I'll throw a couple of questions out there anyway: would it resolve the ambiguity if we required script authors to include
to make it unambiguous that any arguments passed to the script itself would be interpreted as arguments to the script rather than as arguments to
would it help to add a top-level command, called
|
This is not so easy. If you execute
I did something like this here #410. It's quite dirty, as cheats the caseapp library, but it works |
offhand, looks fine to me. it's still fairly early days for this project, so I'll be content with anything that gets me unstuck, and that PR looks like it will. |
It will be available in the upcoming release |
Ok, scala-cli 0.0.9 is out. Your case will work if you use |
tried it out but was blocked by #451 |
(#451 remains an unreproducible mystery, but:) yay, this is now working for me for the community build scripts: scala/community-build#1518 👏 |
Thank you @SethTisue ! |
the docs say that a hello world script is desugared to:
this leaves me unable to reference
args
I don't see any information about this on the doc page I linked above
(context: I was hoping I could replace the combination of https://github.com/scala/community-build/blob/2.13.x/advance and https://github.com/scala/community-build/blob/2.13.x/scripts/Advance.scala with a single
.sc
file, but this is blocking me)The text was updated successfully, but these errors were encountered: