[main] initial parsing of command line args

This commit is contained in:
Paul Campbell 2019-05-06 10:50:41 +01:00
parent 14205f4fbf
commit 8a18171d7d
2 changed files with 24 additions and 1 deletions

View file

@ -6,6 +6,7 @@ scalaVersion := "2.12.8"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.7" % "test"
libraryDependencies += "org.typelevel" %% "cats-effect" % "1.3.0" withSources() withJavadoc()
libraryDependencies += "com.github.scopt" %% "scopt" % "4.0.0-RC2"
scalacOptions ++= Seq(
"-feature",

View file

@ -5,13 +5,35 @@ import cats.effect.{ExitCode, IO, IOApp}
object Main extends IOApp {
def parseArgs(args: List[String]): IO[Config] = IO.pure(Config("", ""))
def parseArgs(args: List[String]): IO[Config] = {
import scopt.OParser
val builder = OParser.builder[Config]
val configParser: OParser[Unit, Config] = {
import builder._
OParser.sequence(
programName("S3Thorp"),
head("s3thorp", "0.1.0"),
opt[String]('b', "bucket")
.action((str, c) => c.copy(bucket = str))
.text("S3 bucket name"),
opt[String]('p', "prefix")
.action((str, c) => c.copy(prefix = str))
.text("Prefix within the S3 Bucket")
)
}
val defaultConfig = Config("def-bucket", "def-prefix")
OParser.parse(configParser, args, defaultConfig) match {
case Some(config) => IO.pure(config)
case _ => IO.raiseError(new IllegalArgumentException)
}
}
def putStrLn(value: String) = IO { println(value) }
def sync(c: Config): IO[Unit] =
for {
_ <- putStrLn("S3Thorp - hashed sync for s3")
_ <- putStrLn(s"Bucket: ${c.bucket}, Prefix: ${c.prefix}")
} yield ()
def program(args: List[String]): IO[ExitCode] =