Integrate MainAnnotation with scala-cli scripts #864
anatoliykmetyuk
started this conversation in
Ideas
Replies: 2 comments
-
Look's like a useful feature, and in the Scala spirit of generalizing concepts and allowing libraries to enable features. Nice! :) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Could this mechanism also be used for cats-effect's IOApp? In //foo.scala
import cats.effect._
object Main extends IOApp.Simple {
override def run: IO[Unit] = IO.println("foo")
} In //foo.sc
//> MainAnnotation: cats.effect.IOApp
IO.println("foo") |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
scala-cli can be used to execute scripts. A CLI script file,
*.sc
, performs the same role as the@main
annotation in a normal Scala program: it marks a block of code as a runnable program.There is a pending PR to Dotty that aims to allow users to define their own annotations similar to
@main
(docs in PR). This mechanism can be used e.g. by framework authors to provide their users with a standard way to run the program based on their library. For example, in Cask, to define an application you need to extendcask.MainRoutes
class.It would be good to also allow scala-cli scripts to support the customization mechanism like that. For example, take the following file from Cask documentation:
I propose to be able to write it as a Scala CLI script as follows:
Notice how the class definition and the
initialize()
call go away – abstracted to the referenced macro.The impact of the above is a simplified way to get started not only with basic scripts but more complex programs like a web server.
Beta Was this translation helpful? Give feedback.
All reactions