[main] Add source directory config option

This commit is contained in:
Paul Campbell 2019-05-06 10:54:42 +01:00
parent 8a18171d7d
commit a4cf1d716b
2 changed files with 6 additions and 3 deletions

View file

@ -1,7 +1,8 @@
package net.kemitix.s3thorp package net.kemitix.s3thorp
case class Config(bucket: String, case class Config(bucket: String,
prefix: String prefix: String,
source: String
) { ) {
} }

View file

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