So I am trying to use decline within Ammonite and there doesn't seem to be a good uesr guide on how to do this. From the docs on Ammonite, i.e. https://ammonite.io/#ScriptArguments you can access the command line arguments by doing the following
@main
def entrypoint(args: String*) = {
}
Assuming you have a an app MyApp as follows (taken from example)
object MyApp extends CommandApp(
name = "my-app",
header = "This compiles to JavaScript!",
main = {
val loudOpt = Opts.flag("loud", "Do something noisy!").orFalse
for (loud <- loudOpt) yield {
if (loud) println("HELLO WORLD!")
else println("hello world!")
}
}
)
You would do something like this
@main
def entrypoint(args: String*) = {
MyApp.main(args.toArray)
}
The problem is that the main method in CommandApp is apparently deprecated, i.e.
@deprecated(
"""
The CommandApp.main method is not intended to be called by user code.
For suggested usage, see: http://monovore.com/decline/usage.html#defining-an-application""",
"0.3.0"
)
final def main(args: Array[String]): Unit =
command.parse(PlatformApp.ambientArgs getOrElse args, sys.env) match {
case Left(help) => System.err.println(help)
case Right(_) => ()
}
Ontop of this the command variable inside the CommandApp class is not publicly visible outside the class (its missing the val modifier in the constructor) so its not like you can manually do MyApp.command.parse (should this deprecated method main be removed in the future). So how exactly is one meant to manually parse args to a CommandApp without using the deprecated main method? For example https://ben.kirw.in/decline/scalajs.html#ambient-arguments details how to get the args on various platforms but never how to pass it into a CommandApp and the provided link at https://ben.kirw.in/decline/usage.html#defining-an-application details how you can manually use args when you have a Command but not when you have a CommandApp (this goes to the previous problem where the command inside the CommandApp is not publicly visible).
Conclusively I guess I also don't understand why the CommandApp.main method is deprecated, if you are using something like Ammonite it is by far the easiest way to make the repl/scripts work with an existing CommandApp (which is the ideal way to use decline). This would also be the case for any other kind of dynamic repl/interactive session where args are passed in a different way.
So I am trying to use decline within Ammonite and there doesn't seem to be a good uesr guide on how to do this. From the docs on Ammonite, i.e. https://ammonite.io/#ScriptArguments you can access the command line arguments by doing the following
Assuming you have a an app
MyAppas follows (taken from example)You would do something like this
The problem is that the
mainmethod inCommandAppis apparently deprecated, i.e.Ontop of this the
commandvariable inside theCommandAppclass is not publicly visible outside the class (its missing thevalmodifier in the constructor) so its not like you can manually doMyApp.command.parse(should this deprecated methodmainbe removed in the future). So how exactly is one meant to manually parseargsto aCommandAppwithout using the deprecatedmainmethod? For example https://ben.kirw.in/decline/scalajs.html#ambient-arguments details how to get theargson various platforms but never how to pass it into aCommandAppand the provided link at https://ben.kirw.in/decline/usage.html#defining-an-application details how you can manually useargswhen you have aCommandbut not when you have aCommandApp(this goes to the previous problem where thecommandinside theCommandAppis not publicly visible).Conclusively I guess I also don't understand why the
CommandApp.mainmethod is deprecated, if you are using something like Ammonite it is by far the easiest way to make the repl/scripts work with an existingCommandApp(which is the ideal way to use decline). This would also be the case for any other kind of dynamic repl/interactive session whereargsare passed in a different way.