From 28c591fa51ce97c9d5b463582e15d5fe8470ecda Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 27 Feb 2021 20:08:27 +0000 Subject: Moved to use scopt Removed weight because of transitive dependencies (com.monovore uses cats). --- build.sc | 2 +- .../src/net/usebox/gemini/server/ServerApp.scala | 45 +++++++--------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/build.sc b/build.sc index 3d29c2f..c058222 100644 --- a/build.sc +++ b/build.sc @@ -21,7 +21,7 @@ object server extends ScalaModule with ScalafmtModule with BuildInfo { def ivyDeps = Agg( ivy"com.github.pureconfig::pureconfig:0.14.0", - ivy"com.monovore::decline:1.3.0", + ivy"com.github.scopt::scopt:4.0.0", ivy"org.log4s::log4s:1.8.2", ivy"ch.qos.logback:logback-classic:1.2.3", ivy"com.typesafe.akka::akka-stream:2.6.12", diff --git a/server/src/net/usebox/gemini/server/ServerApp.scala b/server/src/net/usebox/gemini/server/ServerApp.scala index 068ea6b..88e3b32 100644 --- a/server/src/net/usebox/gemini/server/ServerApp.scala +++ b/server/src/net/usebox/gemini/server/ServerApp.scala @@ -1,9 +1,5 @@ package net.usebox.gemini.server -import com.monovore.decline._ - -import cats.implicits._ - import org.log4s._ object ServerApp { @@ -14,38 +10,24 @@ object ServerApp { val defConfFile = "/etc/spacebeans.conf" case class ServerOpts( - version: Boolean, confFile: String ) - val opts: Command[ServerOpts] = - Command( - name = BuildInfo.name, - header = appName - ) { - ( - Opts - .flag("version", "Display the version and exit.") - .orFalse, - Opts - .option[String]( - "conf", - s"Configuration file (default: $defConfFile).", - short = "c" - ) - .withDefault(defConfFile) - ).mapN { (version, confFile) => - ServerOpts(version, confFile) - } - } + val parser = new scopt.OptionParser[ServerOpts](BuildInfo.name) { + head(appName, BuildInfo.version) + + opt[String]('c', "conf") + .action((x, c) => c.copy(confFile = x)) + .text(s"Configuration file (default: $defConfFile)") + + help("help").text("Displays this help and exits") + version("version") + note("\nProject page: https://github.com/reidrac/spacebeans") + } def main(args: Array[String]): Unit = - opts.parse(args.toIndexedSeq) match { - case Left(help) => - println(help) - case Right(ServerOpts(true, _)) => - println(version) - case Right(ServerOpts(_, confFile)) => + parser.parse(args, ServerOpts(defConfFile)) match { + case Some(ServerOpts(confFile)) => ServiceConf.load(confFile) match { case Left(error) => logger @@ -58,5 +40,6 @@ object ServerApp { ) Server(conf).serve } + case None => // will display error } } -- cgit v1.2.3