Skip to content

Commit

Permalink
upgrade zio version (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgfraser authored May 4, 2022
1 parent 3f86386 commit bd8bf61
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 212 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ inThisBuild(
addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")

val zioVersion = "2.0.0-RC5"
val zioVersion = "2.0.0-RC6"

lazy val root = project
.in(file("."))
Expand Down
7 changes: 4 additions & 3 deletions examples/shared/src/main/scala/zio/cli/examples/WcApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ object WcApp extends ZIOAppDefault {
zio.Console.printLine(s"executing wc with args: $opts $paths").! *>
ZIO
.foreachPar[Any, Throwable, Path, WcResult, List](paths)({ path =>
def option(bool: Boolean, sink: ZSink[Any, Nothing, Byte, Byte, Long])
: ZSink[Any, Nothing, Byte, Byte, Option[Long]] =
def option(bool: Boolean, sink: ZSink[Any, Throwable, Byte, Byte, Long])
: ZSink[Any, Throwable, Byte, Byte, Option[Long]] =
if (bool) sink.map(Some(_)) else ZSink.succeed(None)

val byteCount = option(opts.bytes, ZSink.count)
Expand All @@ -75,7 +75,8 @@ object WcApp extends ZIOAppDefault {
val charCount =
option(opts.char, ZPipeline.utfDecode >>> ZSink.foldLeft[String, Long](0L)((s, e) => s + e.length))

val zippedSinks: ZSink[Any, Nothing, Byte, Byte, (Option[Long], Option[Long], Option[Long], Option[Long])] =
val zippedSinks
: ZSink[Any, Throwable, Byte, Byte, (Option[Long], Option[Long], Option[Long], Option[Long])] =
(byteCount <&> lineCount <&> wordCount <&> charCount)

ZStream
Expand Down
14 changes: 7 additions & 7 deletions zio-cli/shared/src/main/scala/zio/cli/Args.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.time.{
ZoneOffset => JZoneOffset,
ZonedDateTime => JZonedDateTime
}
import zio.{IO, Zippable}
import zio.{IO, ZIO, Zippable}
import zio.cli.HelpDoc.Span

/**
Expand Down Expand Up @@ -94,7 +94,7 @@ object Args {
case (None, Some(choices)) => s"Missing argument ${primType.typeName} with values $choices."
case (None, None) => s"Missing argument ${primType.typeName}."
}
IO.fail(HelpDoc.p(msg))
ZIO.fail(HelpDoc.p(msg))
}

private def name: String = "<" + pseudoName.getOrElse(primType.typeName) + ">"
Expand All @@ -112,7 +112,7 @@ object Args {
def synopsis: UsageSynopsis = UsageSynopsis.None

def validate(args: List[String], conf: CliConfig): IO[HelpDoc, (List[String], Unit)] =
IO.succeed((args, ()))
ZIO.succeed((args, ()))
}

final case class Both[+A, +B](head: Args[A], tail: Args[B]) extends Args[(A, B)] {
Expand Down Expand Up @@ -165,12 +165,12 @@ object Args {
val max1 = max.getOrElse(Int.MaxValue)

def loop(args: List[String], acc: List[A]): IO[HelpDoc, (List[String], List[A])] =
if (acc.length >= max1) IO.succeed(args -> acc)
if (acc.length >= max1) ZIO.succeed(args -> acc)
else
value
.validate(args, conf)
.foldZIO(
failure => if (acc.length >= min1 && args.isEmpty) IO.succeed(args -> acc) else IO.fail(failure),
failure => if (acc.length >= min1 && args.isEmpty) ZIO.succeed(args -> acc) else ZIO.fail(failure),
{ case (args, a) => loop(args, a :: acc) }
)

Expand All @@ -192,8 +192,8 @@ object Args {
def validate(args: List[String], conf: CliConfig): IO[HelpDoc, (List[String], B)] =
value.validate(args, conf).flatMap { case (r, a) =>
f(a) match {
case Left(value) => IO.fail(value)
case Right(value) => IO.succeed((r, value))
case Left(value) => ZIO.fail(value)
case Right(value) => ZIO.succeed((r, value))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions zio-cli/shared/src/main/scala/zio/cli/CliConfig.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package zio.cli

import zio.URIO
import zio.{URIO, ZIO}

/**
* A `CliConfig` describes how arguments from the command-line are to
Expand Down Expand Up @@ -29,5 +29,5 @@ object CliConfig {
*/
val default: CliConfig = CliConfig(caseSensitive = false, autoCorrectLimit = 2)

val cliConfig: URIO[CliConfig, CliConfig] = URIO.service
val cliConfig: URIO[CliConfig, CliConfig] = ZIO.service
}
12 changes: 6 additions & 6 deletions zio-cli/shared/src/main/scala/zio/cli/Command.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ object Command {
if (args.headOption.exists(conf.normalizeCase(_) == conf.normalizeCase(name)))
builtIn(args, conf)
else
IO.fail(None)
ZIO.fail(None)

def synopsis: UsageSynopsis =
UsageSynopsis.Named(name, None) + options.synopsis + args.synopsis
Expand All @@ -138,16 +138,16 @@ object Command {
for {
args <- args match {
case head :: tail =>
if (conf.normalizeCase(head) == conf.normalizeCase(name)) IO.succeed(tail)
if (conf.normalizeCase(head) == conf.normalizeCase(name)) ZIO.succeed(tail)
else
IO.fail(
ZIO.fail(
ValidationError(
ValidationErrorType.CommandMismatch,
HelpDoc.p(s"Unexpected command name: ${args.headOption}")
)
)
case Nil =>
IO.fail(
ZIO.fail(
ValidationError(ValidationErrorType.CommandMismatch, HelpDoc.p(s"Missing command name: ${name}"))
)
}
Expand Down Expand Up @@ -231,9 +231,9 @@ object Command {
CommandDirective.builtIn(BuiltInOption.ShowHelp(self.helpDoc))
))
help <- help match {
case CommandDirective.BuiltIn(BuiltInOption.ShowHelp(h)) => IO.succeed(h)
case CommandDirective.BuiltIn(BuiltInOption.ShowHelp(h)) => ZIO.succeed(h)
case _ =>
IO.fail(
ZIO.fail(
ValidationError(
ValidationErrorType.InvalidArgument,
HelpDoc.empty
Expand Down
24 changes: 12 additions & 12 deletions zio-cli/shared/src/main/scala/zio/cli/Options.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.time.{
ZoneOffset => JZoneOffset,
ZonedDateTime => JZonedDateTime
}
import zio.{IO, UIO, Zippable}
import zio.{IO, ZIO, Zippable}
import zio.cli.HelpDoc.Span
import zio.cli.HelpDoc.p
import zio.cli.HelpDoc.Span._
Expand Down Expand Up @@ -183,7 +183,7 @@ object Options {
def synopsis: UsageSynopsis = UsageSynopsis.None

def validate(args: List[String], conf: CliConfig): IO[ValidationError, (List[String], Unit)] =
IO.succeed((args, ()))
ZIO.succeed((args, ()))

override def modifySingle(f: SingleModifier): Options[Unit] = Empty

Expand All @@ -200,7 +200,7 @@ object Options {
options
.validate(args, conf)
.catchSome {
case error if error.isOptionMissing => UIO.succeed(args -> default)
case error if error.isOptionMissing => ZIO.succeed(args -> default)
}

override def modifySingle(f: SingleModifier): Options[A] =
Expand Down Expand Up @@ -256,7 +256,7 @@ object Options {
fullName,
conf
) <= conf.autoCorrectLimit =>
IO.fail(
ZIO.fail(
ValidationError(
ValidationErrorType.MissingValue,
p(error(s"""The flag "$head" is not recognized. Did you mean $fullName?"""))
Expand All @@ -267,7 +267,7 @@ object Options {
(head :: args, a)
}
case Nil =>
IO.fail(ValidationError(ValidationErrorType.MissingValue, p(error(s"Expected to find $fullName option."))))
ZIO.fail(ValidationError(ValidationErrorType.MissingValue, p(error(s"Expected to find $fullName option."))))
}

def uid: Option[String] = Some(fullName)
Expand Down Expand Up @@ -306,7 +306,7 @@ object Options {
.validate(args, conf)
.foldZIO[Any, ValidationError, (List[String], Either[A, B])](
err2 =>
IO.fail(
ZIO.fail(
// orElse option is only missing in case neither option was given
(err1.validationErrorType, err2.validationErrorType) match {
case (ValidationErrorType.MissingValue, ValidationErrorType.MissingValue) =>
Expand All @@ -315,15 +315,15 @@ object Options {
ValidationError(ValidationErrorType.InvalidValue, err1.error + err2.error)
}
),
success => IO.succeed((success._1, Right(success._2)))
success => ZIO.succeed((success._1, Right(success._2)))
),
r =>
right
.validate(r._1, conf)
.foldZIO(
_ => IO.succeed((r._1, Left(r._2))),
_ => ZIO.succeed((r._1, Left(r._2))),
_ =>
IO.fail(
ZIO.fail(
ValidationError(
ValidationErrorType.InvalidValue,
p(error(s"Options collision detected. You can only specify either $left or $right."))
Expand Down Expand Up @@ -353,8 +353,8 @@ object Options {
right
.validate(args, conf)
.foldZIO(
err2 => IO.fail(ValidationError(ValidationErrorType.MissingValue, err1.error + err2.error)),
_ => IO.fail(err1)
err2 => ZIO.fail(ValidationError(ValidationErrorType.MissingValue, err1.error + err2.error)),
_ => ZIO.fail(err1)
)
)
(args, a) = tuple
Expand All @@ -376,7 +376,7 @@ object Options {
def synopsis: UsageSynopsis = value.synopsis

def validate(args: List[String], conf: CliConfig): IO[ValidationError, (List[String], B)] =
value.validate(args, conf).flatMap(r => f(r._2).fold(e => IO.fail(e), s => IO.succeed(r._1 -> s)))
value.validate(args, conf).flatMap(r => f(r._2).fold(e => ZIO.fail(e), s => ZIO.succeed(r._1 -> s)))

override def uid: Option[String] = value.uid

Expand Down
12 changes: 6 additions & 6 deletions zio-cli/shared/src/main/scala/zio/cli/PrimType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ object PrimType {
def validate(value: Option[String], conf: CliConfig): IO[String, A] =
(ZIO.fromOption(value) orElseFail "Enumeration options do not have a default value.").flatMap { value =>
cases.find(_._1 == value) match {
case None => IO.fail("Expected one of the following cases: " + cases.map(_._1).mkString(", "))
case Some((_, a)) => IO.succeed(a)
case None => ZIO.fail("Expected one of the following cases: " + cases.map(_._1).mkString(", "))
case Some((_, a)) => ZIO.succeed(a)
}
}
}
Expand Down Expand Up @@ -174,10 +174,10 @@ object PrimType {

def validate(value: Option[String], conf: CliConfig): IO[String, Boolean] =
value.map(conf.normalizeCase) match {
case Some(s) if Bool.TrueValues(s) => IO.succeed(true)
case Some(s) if Bool.FalseValues(s) => IO.succeed(false)
case Some(s) => IO.fail(s"$s cannot be recognized as valid boolean.")
case None => IO.fromOption(defaultValue).orElseFail("Missing default for bool parameter.")
case Some(s) if Bool.TrueValues(s) => ZIO.succeed(true)
case Some(s) if Bool.FalseValues(s) => ZIO.succeed(false)
case Some(s) => ZIO.fail(s"$s cannot be recognized as valid boolean.")
case None => ZIO.fromOption(defaultValue).orElseFail("Missing default for bool parameter.")
}

def helpDoc: HelpDoc.Span = text("A true or false value.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object Completion {
val derivative: UIO[RegularLanguage] = ZIO.foldLeft(unclustered)(language)((lang, word) =>
lang
.derive(word)
.provideService(cliConfig)
.provideEnvironment(ZEnvironment(cliConfig))
)

val wordToComplete = if (index < words.size) words(index) else ""
Expand Down
6 changes: 3 additions & 3 deletions zio-cli/shared/src/main/scala/zio/cli/files/FileSystem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ object FileSystem {
ZIO.attempt(JPaths.get(path)) orElseFail s"'$path' is not a recognized path."

override def exists(path: JPath): UIO[Boolean] =
ZIO.attempt(JFiles.exists(path)) orElse IO.succeed(false)
ZIO.attempt(JFiles.exists(path)) orElse ZIO.succeed(false)

override def isDirectory(path: JPath): UIO[Boolean] =
ZIO.attempt(JFiles.isDirectory(path)) orElse IO.succeed(false)
ZIO.attempt(JFiles.isDirectory(path)) orElse ZIO.succeed(false)

override def isRegularFile(path: JPath): UIO[Boolean] =
ZIO.attempt(JFiles.isRegularFile(path)) orElse IO.succeed(false)
ZIO.attempt(JFiles.isRegularFile(path)) orElse ZIO.succeed(false)
}

}
Loading

0 comments on commit bd8bf61

Please sign in to comment.