@@ -11,8 +11,8 @@ import zio.console.{Console, putStrLn}
1111import java .io .IOException
1212
1313/**
14- * Adapted from caseapp.cats.IOCaseApp
15- */
14+ * Adapted from caseapp.cats.IOCaseApp
15+ */
1616abstract class ZCaseApp [T ](implicit val parser0 : Parser [T ], val messages : Help [T ]) extends App {
1717
1818 private [this ] def parser : Parser [T ] = {
@@ -35,42 +35,44 @@ abstract class ZCaseApp[T](implicit val parser0: Parser[T], val messages: Help[T
3535 putStrLn(messages.withHelp.usage).as(ExitCode .success)
3636
3737 /**
38- * Arguments are expanded then parsed. By default, argument expansion is the identity function.
39- * Overriding this method allows plugging in an arbitrary argument expansion logic.
40- *
41- * One such expansion logic involves replacing each argument of the form '@<file>' with the
42- * contents of that file where each line in the file becomes a distinct argument.
43- * To enable this behavior, override this method as shown below.
44- *
45- * @example
46- * {{{
47- * import caseapp.core.parser.PlatformArgsExpander
48- * override def expandArgs(args: List[String]): List[String]
49- * = PlatformArgsExpander.expand(args)
50- * }}}
51- * @param args
52- * @return
53- */
38+ * Arguments are expanded then parsed. By default, argument expansion is the identity function.
39+ * Overriding this method allows plugging in an arbitrary argument expansion logic.
40+ *
41+ * One such expansion logic involves replacing each argument of the form '@<file>' with the
42+ * contents of that file where each line in the file becomes a distinct argument.
43+ * To enable this behavior, override this method as shown below.
44+ *
45+ * @example
46+ * {{{
47+ * import caseapp.core.parser.PlatformArgsExpander
48+ * override def expandArgs(args: List[String]): List[String]
49+ * = PlatformArgsExpander.expand(args)
50+ * }}}
51+ * @param args
52+ * @return
53+ */
5454 private [this ] def expandArgs (args : List [String ]): List [String ] = args
5555
5656 /**
57- * Whether to stop parsing at the first unrecognized argument.
58- *
59- * That is, stop parsing at the first non option (not starting with "-"), or
60- * the first unrecognized option. The unparsed arguments are put in the `args`
61- * argument of `run`.
62- */
57+ * Whether to stop parsing at the first unrecognized argument.
58+ *
59+ * That is, stop parsing at the first non option (not starting with "-"), or
60+ * the first unrecognized option. The unparsed arguments are put in the `args`
61+ * argument of `run`.
62+ */
6363 private [this ] def stopAtFirstUnrecognized : Boolean = false
6464
6565 private [this ] def nameFormatter : Formatter [Name ] = Formatter .DefaultNameFormatter
6666
67- override def run (args : List [String ]): ZIO [ZEnv , Nothing , ExitCode ] =
68- parser.withHelp.detailedParse(expandArgs(args), stopAtFirstUnrecognized) match {
69- case Left (err) => error(err).orDie
70- case Right ((WithHelp (_, true , _), _)) => helpAsked.orDie
71- case Right ((WithHelp (true , _, _), _)) => usageAsked.orDie
72- case Right ((WithHelp (_, _, Left (err)), _)) => error(err).orDie
67+ override def run (args : List [String ]): ZIO [ZEnv , Nothing , ExitCode ] = {
68+ if (args == List (" --version" )) ZIO .succeed(println(org.renci.relationgraph.BuildInfo .toString)).exitCode
69+ else parser.withHelp.detailedParse(expandArgs(args), stopAtFirstUnrecognized) match {
70+ case Left (err) => error(err).orDie
71+ case Right ((WithHelp (_, true , _), _)) => helpAsked.orDie
72+ case Right ((WithHelp (true , _, _), _)) => usageAsked.orDie
73+ case Right ((WithHelp (_, _, Left (err)), _)) => error(err).orDie
7374 case Right ((WithHelp (_, _, Right (t)), remainingArgs)) => run(t, remainingArgs)
7475 }
76+ }
7577
7678}
0 commit comments