Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Colorize opts into companion object #1369

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions core/src/main/scala/org/bykn/bosatsu/LocationMap.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.bykn.bosatsu

import cats.data.{Validated, ValidatedNel}
import com.monovore.decline.{Argument, Opts}
import org.typelevel.paiges.Doc
import cats.parse.{LocationMap => CPLocationMap}

Expand Down Expand Up @@ -144,6 +146,26 @@ object LocationMap {
"</font>"
)
}

implicit val argColor: Argument[Colorize] =
new Argument[Colorize] {
def defaultMetavar: String = "color"
def read(str: String): ValidatedNel[String, Colorize] =
str.toLowerCase match {
case "none" => Validated.valid(Colorize.None)
case "ansi" => Validated.valid(Colorize.Console)
case "html" => Validated.valid(Colorize.HmtlFont)
case other =>
Validated.invalidNel(
s"unknown colorize: $other, expected: none, ansi or html"
)
}
}

val opts: Opts[Colorize] =
Opts.option[Colorize]("color", help = "colorize mode: none, ansi or html")

val optsConsoleDefault: Opts[Colorize] = opts.orElse(Opts(Colorize.Console))
}

/** Provide a string that points with a carat to a given column with 0 based
Expand Down
39 changes: 13 additions & 26 deletions core/src/main/scala/org/bykn/bosatsu/MainModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -760,25 +760,6 @@ class MainModule[IO[_], Path](val platformIO: PlatformIO[IO, Path]) {
"Must be a package name with an optional :: value, e.g. Foo/Bar or Foo/Bar::baz."
)

implicit val argColor: Argument[Colorize] =
new Argument[Colorize] {
def defaultMetavar: String = "color"
def read(str: String): ValidatedNel[String, Colorize] =
str.toLowerCase match {
case "none" => Validated.valid(Colorize.None)
case "ansi" => Validated.valid(Colorize.Console)
case "html" => Validated.valid(Colorize.HmtlFont)
case other =>
Validated.invalidNel(
s"unknown colorize: $other, expected: none, ansi or html"
)
}
}

val colorOpt = Opts
.option[Colorize]("color", help = "colorize mode: none, ansi or html")
.orElse(Opts(Colorize.Console))

val mainP =
MainIdentifier.opts(
Opts.option[(PackageName, Option[Bindable])](
Expand Down Expand Up @@ -815,7 +796,13 @@ class MainModule[IO[_], Path](val platformIO: PlatformIO[IO, Path]) {

val jsonCommand = {
def toJsonOpt(modeOpt: Opts[JsonMode]) =
(Inputs.runtimeOpts, modeOpt, mainP, outputPath.orNone, colorOpt)
(
Inputs.runtimeOpts,
modeOpt,
mainP,
outputPath.orNone,
Colorize.optsConsoleDefault
)
.mapN(ToJson(_, _, _, _, _))

val input: Opts[JsonInput] =
Expand Down Expand Up @@ -853,7 +840,7 @@ class MainModule[IO[_], Path](val platformIO: PlatformIO[IO, Path]) {

val transpileOpt = (
Inputs.runtimeOpts,
colorOpt,
Colorize.optsConsoleDefault,
transOpt,
Opts.option[Path](
"outdir",
Expand All @@ -862,18 +849,18 @@ class MainModule[IO[_], Path](val platformIO: PlatformIO[IO, Path]) {
)
.mapN(TranspileCommand(_, _, _, _))

val evalOpt = (Inputs.runtimeOpts, mainP, colorOpt)
val evalOpt = (Inputs.runtimeOpts, mainP, Colorize.optsConsoleDefault)
.mapN(Evaluate(_, _, _))

val typeCheckOpt = (
Inputs.compileOpts,
outputPath.orNone,
interfaceOutputPath.orNone,
colorOpt
Colorize.optsConsoleDefault
)
.mapN(Check(_, _, _, _))

val testOpt = (Inputs.runtimeOpts, testP, colorOpt)
val testOpt = (Inputs.runtimeOpts, testP, Colorize.optsConsoleDefault)
.mapN(RunTests(_, _, _))

Opts
Expand All @@ -897,7 +884,7 @@ class MainModule[IO[_], Path](val platformIO: PlatformIO[IO, Path]) {
)
.orElse(
Opts.subcommand("show", "show compiled packages")(
(Inputs.showOpts, outputPath.orNone, colorOpt)
(Inputs.showOpts, outputPath.orNone, Colorize.optsConsoleDefault)
.mapN(Show(_, _, _))
)
)
Expand All @@ -906,7 +893,7 @@ class MainModule[IO[_], Path](val platformIO: PlatformIO[IO, Path]) {
(
Inputs.depsOpts,
outputPath.orNone,
colorOpt,
Colorize.optsConsoleDefault,
GraphOutput.jsonOrDot
)
.mapN(Deps(_, _, _, _))
Expand Down
Loading