File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
main/scala/org/scalasteward/core/application
test/scala/org/scalasteward/core/application Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 1717package org .scalasteward .core .application
1818
1919import caseapp ._
20- import caseapp .core .Error .MalformedValue
20+ import caseapp .core .Error .{ MalformedValue , Other }
2121import caseapp .core .argparser .{ArgParser , SimpleArgParser }
2222import cats .syntax .all ._
2323import org .http4s .Uri
@@ -29,7 +29,15 @@ import scala.concurrent.duration._
2929final class Cli [F [_]](implicit F : ApplicativeThrowable [F ]) {
3030 def parseArgs (args : List [String ]): F [Args ] =
3131 F .fromEither {
32- CaseApp .parse[Args ](args).bimap(e => new Throwable (e.message), { case (parsed, _) => parsed })
32+ CaseApp
33+ .parseWithHelp[Args ](args)
34+ .flatMap {
35+ case (_, true , _, _) => Left (Other (CaseApp .helpMessage[Args ]))
36+ case (_, _, true , _) => Left (Other (CaseApp .usageMessage[Args ]))
37+ case (parsed @ Right (_), _, _, _) => parsed
38+ case (e @ Left (_), _, _, _) => e
39+ }
40+ .leftMap(e => new Throwable (e.message))
3341 }
3442}
3543
Original file line number Diff line number Diff line change 11package org .scalasteward .core .application
2+
23import org .http4s .syntax .literals ._
34import org .scalasteward .core .application .Cli .EnvVar
5+ import org .scalatest .EitherValues
46import org .scalatest .funsuite .AnyFunSuite
57import org .scalatest .matchers .should .Matchers
68import scala .concurrent .duration ._
79
8- class CliTest extends AnyFunSuite with Matchers {
10+ class CliTest extends AnyFunSuite with Matchers with EitherValues {
911 type Result [A ] = Either [Throwable , A ]
1012 val cli : Cli [Result ] = new Cli [Result ]
1113
@@ -66,6 +68,14 @@ class CliTest extends AnyFunSuite with Matchers {
6668 cli.parseArgs(Nil ).isLeft shouldBe true
6769 }
6870
71+ test(" parseArgs --help" ) {
72+ cli.parseArgs(List (" --help" )).left.value.getMessage should include(" --git-author-email" )
73+ }
74+
75+ test(" parseArgs --usage" ) {
76+ cli.parseArgs(List (" --usage" )).left.value.getMessage should startWith(" Usage: args" )
77+ }
78+
6979 test(" env-var without equals sign" ) {
7080 Cli .envVarArgParser(None , " SBT_OPTS" ).isLeft shouldBe true
7181 }
You can’t perform that action at this time.
0 commit comments