diff --git a/src/main/scala/net/kemitix/s3thorp/Main.scala b/src/main/scala/net/kemitix/s3thorp/Main.scala index a6fda47..5d49d30 100644 --- a/src/main/scala/net/kemitix/s3thorp/Main.scala +++ b/src/main/scala/net/kemitix/s3thorp/Main.scala @@ -1,5 +1,7 @@ package net.kemitix.s3thorp +import java.nio.file.Paths + import cats.effect.ExitCase.{Canceled, Completed, Error} import cats.effect.{ExitCode, IO, IOApp} @@ -7,10 +9,13 @@ object Main extends IOApp { def putStrLn(value: String) = IO { println(value) } + val defaultConfig: Config = + Config("(none)", "", Paths.get(".").toAbsolutePath) + def program(args: List[String]): IO[ExitCode] = for { _ <- putStrLn("S3Thorp - hashed sync for s3") - a <- ParseArgs(args) + a <- ParseArgs(args, defaultConfig) _ <- Sync(a) } yield ExitCode.Success diff --git a/src/main/scala/net/kemitix/s3thorp/ParseArgs.scala b/src/main/scala/net/kemitix/s3thorp/ParseArgs.scala index 941b384..8559d09 100644 --- a/src/main/scala/net/kemitix/s3thorp/ParseArgs.scala +++ b/src/main/scala/net/kemitix/s3thorp/ParseArgs.scala @@ -1,8 +1,10 @@ package net.kemitix.s3thorp -import scopt.OParser -import scopt.OParser.{builder,sequence, parse} +import java.nio.file.Paths + import cats.effect.IO +import scopt.OParser +import scopt.OParser.{builder, parse, sequence} object ParseArgs { @@ -13,7 +15,7 @@ object ParseArgs { programName("S3Thorp"), head("s3thorp"), opt[String]('s', "source") - .action((str, c) => c.copy(source = str)) + .action((str, c) => c.copy(source = Paths.get(str))) .required() .text("Source directory to sync to S3"), opt[String]('b', "bucket") @@ -26,8 +28,8 @@ object ParseArgs { ) } - def apply(args: List[String]): IO[Config] = - parse(configParser, args, Config()) match { + def apply(args: List[String], defaultConfig: Config): IO[Config] = + parse(configParser, args, defaultConfig) match { case Some(config) => IO.pure(config) case _ => IO.raiseError(new IllegalArgumentException) } diff --git a/src/main/scala/net/kemitix/s3thorp/Sync.scala b/src/main/scala/net/kemitix/s3thorp/Sync.scala index de8bdea..85a57da 100644 --- a/src/main/scala/net/kemitix/s3thorp/Sync.scala +++ b/src/main/scala/net/kemitix/s3thorp/Sync.scala @@ -1,6 +1,6 @@ package net.kemitix.s3thorp -import java.nio.file.{Path, Paths} +import java.nio.file.Path import java.time.Instant import cats.effect._ @@ -13,7 +13,7 @@ object Sync extends LocalFileStream with S3MetaDataEnricher { def apply(c: Config): IO[Unit] = for { _ <- putStrLn(s"Bucket: ${c.bucket}, Prefix: ${c.prefix}, Source: ${c.source}") _ <- { - streamDirectoryPaths(Paths.get(c.source)).flatMap( + streamDirectoryPaths(c.source).flatMap( enrichWithS3MetaData).flatMap( uploadRequiredFilter).flatMap( performUpload).compile.drain