[main] extract IO program

This commit is contained in:
Paul Campbell 2019-05-06 10:32:53 +01:00
parent b16862ea20
commit b5e1036874

View file

@ -2,16 +2,21 @@ package net.kemitix.s3thorp
import cats.effect.ExitCase.{Canceled, Completed, Error}
import cats.effect.{ExitCode, IO, IOApp}
import cats.syntax.all._
object Main extends IOApp {
def parseArgs(args: List[String]): IO[Config] = IO.pure(Config("", ""))
def program(args: List[String]): IO[ExitCode] = for {
a <- parseArgs(args)
_ <- S3Thorp(a)
} yield ExitCode.Success
override def run(args: List[String]): IO[ExitCode] =
(for {
ec <- S3Thorp(args).as(ExitCode.Success)
} yield ec).guaranteeCase {
program(args)
.guaranteeCase {
case Canceled => IO(println("Interrupted"))
case Error(e) => IO(println("ERROR: " + e))
case Error(e) => IO(println("ERROR: " + e.getMessage))
case Completed => IO(println("Done"))
}