Skip to content

Commit b49bd27

Browse files
committed
output to console is on by default
1 parent 5f19626 commit b49bd27

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

src/main/scala/org/polystat/cli/PolystatOpts.scala

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,11 @@ object PolystatOpts:
164164
private enum OutputArg:
165165
case File(path: Path)
166166
case Directory(path: Path)
167-
case Console
168167
end OutputArg
169168

170169
private given Argument[OutputArg] with
171170
def read(string: String): ValidatedNel[String, OutputArg] =
172-
val KVArg = "(.*)=(.*)".r
171+
val KVArg = "(.+)=(.+)".r
173172
string match
174173
case KVArg(key, value) =>
175174
key match
@@ -183,38 +182,44 @@ object PolystatOpts:
183182
.map(path => OutputArg.File(Path.fromNioPath(path)))
184183
case other =>
185184
Validated.invalidNel(s"Unknown key in `--to` option: $other")
186-
case "console" => Validated.valid(OutputArg.Console)
187-
case other => Validated.invalidNel(s"Unknown argument: $string")
185+
case other => Validated.invalidNel(s"Unknown argument: $string")
188186
end match
189187
end read
190-
def defaultMetavar: String = "console | dir=<path> | file=<path>"
188+
def defaultMetavar: String = "dir=<path> | file=<path>"
191189
end given
192190

193-
def files: Opts[Output] = Opts
191+
private def quiet: Opts[Boolean] = Opts
192+
.flag(
193+
long = "quiet",
194+
help = "Disables console output.",
195+
short = "q",
196+
)
197+
.orFalse
198+
199+
private def outputFiles: Opts[List[OutputArg]] = Opts
194200
.options[OutputArg](
195201
long = "to",
196202
help = "Create output files in the specified path",
197203
)
198204
.orEmpty
199-
.map(args =>
200-
val initialState =
201-
Output(dirs = List(), files = List(), console = false)
202-
args.foldLeft(initialState) { case (acc, arg) =>
203-
arg match
204-
case OutputArg.File(path) =>
205-
acc.copy(files = acc.files.prepended(path))
206-
case OutputArg.Directory(path) =>
207-
acc.copy(dirs = acc.dirs.prepended(path))
208-
case OutputArg.Console =>
209-
if acc.console then acc else acc.copy(console = true)
210-
}
211-
)
205+
206+
def to: Opts[Output] = (outputFiles, quiet).mapN { case (outputArgs, quiet) =>
207+
val notQuiet = !quiet
208+
val initialState = Output(dirs = List(), files = List(), console = notQuiet)
209+
outputArgs.foldLeft(initialState) { case (acc, arg) =>
210+
arg match
211+
case OutputArg.File(path) =>
212+
acc.copy(files = acc.files.prepended(path))
213+
case OutputArg.Directory(path) =>
214+
acc.copy(dirs = acc.dirs.prepended(path))
215+
}
216+
}
212217

213218
def analyzerConfig: Opts[IO[AnalyzerConfig]] =
214-
(inex, in, tmp, outputFormats, files).mapN {
215-
case (inex, in, tmp, outputFormats, out) =>
219+
(inex, in, tmp, outputFormats, to).mapN {
220+
case (inex, in, tmp, outputFormats, to) =>
216221
for in <- in
217-
yield AnalyzerConfig(inex, in, tmp, outputFormats, out)
222+
yield AnalyzerConfig(inex, in, tmp, outputFormats, to)
218223
}
219224

220225
end PolystatOpts

src/main/scala/org/polystat/cli/util/FileTypes.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ object FileTypes:
99
final class Directory private[FileTypes] (
1010
private[FileTypes] val underlying: Path
1111
):
12+
export underlying.{toNioPath, /}
1213
override def toString = underlying.toString
1314
def toPath: Path = underlying
14-
def toNioPath: JPath = underlying.toNioPath
15-
def /(s: String): Path = underlying / s
1615
def clean: IO[Directory] =
1716
for
1817
_ <- Files[IO].deleteRecursively(underlying)
@@ -44,10 +43,9 @@ object FileTypes:
4443
def fromPathUnsafe(path: Path): Directory = Directory(path)
4544

4645
final class File private[FileTypes] (private[FileTypes] val underlying: Path):
46+
export underlying.{toNioPath, extName}
4747
override def toString(): String = underlying.toString
4848
def toPath = underlying
49-
def toNioPath: JPath = underlying.toNioPath
50-
def extName = underlying.extName
5149
def filenameNoExt: String =
5250
val fileName = underlying.fileName.toString
5351
fileName.splitAt(fileName.indexOf("."))._1

0 commit comments

Comments
 (0)