Skip to content

Commit

Permalink
Merge pull request #313 from alexarchambault/dash-help
Browse files Browse the repository at this point in the history
Re-use WithHelp parser in WithFullHelp
  • Loading branch information
alexarchambault authored Jul 26, 2021
2 parents 1b90b2a + 259d6c4 commit 51c1158
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
10 changes: 5 additions & 5 deletions core/shared/src/main/scala/caseapp/core/app/CaseApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ abstract class CaseApp[T](implicit val parser0: Parser[T], val messages: Help[T]
if (hasFullHelp)
parser.withFullHelp.detailedParse(expandArgs(args.toList), stopAtFirstUnrecognized, ignoreUnrecognized) match {
case Left(err) => error(err)
case Right((WithFullHelp(_, _, true, _), _)) => fullHelpAsked(progName)
case Right((WithFullHelp(_, true, _, _), _)) => helpAsked(progName)
case Right((WithFullHelp(true, _, _, _), _)) => usageAsked(progName)
case Right((WithFullHelp(_, _, _, Left(err)), _)) => error(err)
case Right((WithFullHelp(_, _, _, Right(t)), remainingArgs)) => run(t, remainingArgs)
case Right((WithFullHelp(_, true), _)) => fullHelpAsked(progName)
case Right((WithFullHelp(WithHelp(_, true, _), _), _)) => helpAsked(progName)
case Right((WithFullHelp(WithHelp(true, _, _), _), _)) => usageAsked(progName)
case Right((WithFullHelp(WithHelp(_, _, Left(err)), _), _)) => error(err)
case Right((WithFullHelp(WithHelp(_, _, Right(t)), _), remainingArgs)) => run(t, remainingArgs)
}
else if (hasHelp)
parser.withHelp.detailedParse(expandArgs(args.toList), stopAtFirstUnrecognized, ignoreUnrecognized) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ trait Completer[T] { self =>
def withHelp: Completer[WithHelp[T]] =
contramapOpt(_.baseOrError.toOption)
def withFullHelp: Completer[WithFullHelp[T]] =
contramapOpt(_.baseOrError.toOption)
contramapOpt(_.withHelp.baseOrError.toOption)
}
15 changes: 4 additions & 11 deletions core/shared/src/main/scala/caseapp/core/help/WithFullHelp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@ import caseapp.core.Error
import caseapp.{ExtraName, Group, HelpMessage, Recurse}

final case class WithFullHelp[T](
@Group("Help")
@HelpMessage("Print usage and exit")
usage: Boolean = false,
@Group("Help")
@HelpMessage("Print help message and exit")
@ExtraName("h")
help: Boolean = false,
@Recurse
withHelp: WithHelp[T],
@Group("Help")
@HelpMessage("Print help message, including hidden options, and exit")
@ExtraName("fullHelp")
helpFull: Boolean = false,
@Recurse
baseOrError: Either[Error, T]
helpFull: Boolean = false
) {
def map[U](f: T => U): WithFullHelp[U] =
copy(baseOrError = baseOrError.map(f))
copy(withHelp = withHelp.map(f))
}
3 changes: 2 additions & 1 deletion project/Mima.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import scala.sys.process._
object Mima {

def binaryCompatibilityVersions: Set[String] =
Seq("git", "tag", "--merged", "HEAD^", "--contains", "15cf6005e")
Seq("git", "tag", "--merged", "HEAD^", "--contains", "1b90b2ac934eb41d6a82d10bd78561fa91fb4ead")
.!!
.linesIterator
.map(_.trim)
.filter(_.startsWith("v"))
.map(_.stripPrefix("v"))
.filter(_ != "2.1.0-M5")
.toSet

def settings = Def.settings(
Expand Down

0 comments on commit 51c1158

Please sign in to comment.