Skip to content

Commit

Permalink
Remove All use Unit instead
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Sep 25, 2024
1 parent 6bbde3e commit 450fb4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
28 changes: 11 additions & 17 deletions modules/ingestor/src/main/scala/cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,21 @@ object cli
case opts: IndexOpts => index(opts)
case opts: WatchOpts => watch(opts)

import opts.{ All, Single }
def index(opts: IndexOpts): IO[Unit] =
opts.index match
case All =>
case Index.Forum =>
forum.run(opts.since, opts.until, opts.dry).compile.drain
case Index.Study =>
study.run(opts.since, opts.until, opts.dry).compile.drain
case Index.Game =>
game.run(opts.since, opts.until, opts.dry).compile.drain
case Index.Team =>
team.run(opts.since, opts.until, opts.dry).compile.drain
case _ =>
forum.run(opts.since, opts.until, opts.dry).compile.drain *>
study.run(opts.since, opts.until, opts.dry).compile.drain *>
game.run(opts.since, opts.until, opts.dry).compile.drain *>
team.run(opts.since, opts.until, opts.dry).compile.drain
case Single(index) =>
index match
case Index.Forum =>
forum.run(opts.since, opts.until, opts.dry).compile.drain
case Index.Study =>
study.run(opts.since, opts.until, opts.dry).compile.drain
case Index.Game =>
game.run(opts.since, opts.until, opts.dry).compile.drain
case Index.Team =>
team.run(opts.since, opts.until, opts.dry).compile.drain

def watch(opts: WatchOpts): IO[Unit] =
opts.index match
Expand All @@ -79,9 +76,7 @@ object cli
case _ => IO.println("We only support game watch for now")

object opts:
object All
case class Single(index: Index)
case class IndexOpts(index: Single | All.type, since: Instant, until: Instant, dry: Boolean)
case class IndexOpts(index: Index | Unit, since: Instant, until: Instant, dry: Boolean)
case class WatchOpts(index: Index, since: Instant, dry: Boolean)

def parse = Opts.subcommand("index", "index documents")(indexOpt) <+>
Expand All @@ -95,12 +90,11 @@ object opts:
short = "i",
metavar = "forum|team|study|game"
)
.map(Single.apply)

val allIndexOpt =
Opts
.flag(long = "all", help = "All indexes")
.as(All)
.void

val dryOpt =
Opts
Expand Down
2 changes: 1 addition & 1 deletion modules/ingestor/src/test/scala/ClITest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object CLITest extends weaver.FunSuite:
test("index command"):
expect(
testCommand("index", "--index", "team", "--since", "0", "--until", "1", "--dry") ==
IndexOpts(Single(Index.Team), Instant.ofEpochSecond(0), Instant.ofEpochSecond(1), true).asRight
IndexOpts(Index.Team, Instant.ofEpochSecond(0), Instant.ofEpochSecond(1), true).asRight
)

test("watch command"):
Expand Down

0 comments on commit 450fb4b

Please sign in to comment.