@@ -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
220225end PolystatOpts
0 commit comments