-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add support for running snippets #1166
Conversation
modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Two remarks:
- it seems the
--script-snippet
option and all can only be specified a single time each. Is that intended? (to be inline withscala -e
maybe?) Changing their types toList[String]
would allow them to be specified multiple times, which could be handy. - I think it might be possible to preserve the order of these arguments, and add them to the other inputs in the right order too (relative to the other inputs), by using
caseapp.core.Indexed
, likescriptSnippet: List[Indexed[String]]
. We get the other inputs viacaseapp.RemainingArgs
, which also offers the indices of individual arguments. That way, both--*-snippet
options and other inputs would be taken into account in the right order, when computing the default main class for example. (Beware that I didn't useIndexed
much, I hope it works fine…)
These points can be addressed or discussed in later PRs if needed, IMO.
Initially I intended to have it as close to
Hm... the potential benefits of doing this are minimal, if I understand correctly... But I'll try it in a separate PR |
Fixes #1150
Additionally, this allows to run Scala and Java snippets in a similar fashion as
-e
allows for scripts.Context:
-e
/--script-snippet
/--execute-script
allows for running code as a.sc
script; it's similar to piping code viastdin
to_.sc
scala -e
$ scala-cli -e 'println("Hello")' Hello
--scala-snippet
/--execute-scala
allows for running raw.scala
code; it's similar to piping code viastdin
to_.scala
$ scala-cli --scala-snippet '@main def run() = println("Hello")' Hello
--java-snippet
/--execute-java
allows for running raw.java
code; it's similar to piping code viastdin
to_.java
$ scala-cli --java-snippet 'public class Main { public static void main(String[] args) { System.out.println("Hello"); } }' Hello