mirror of https://github.com/sbt/sbt.git
Tweak some type class derivations
Hopefully will address more-or-less random failures, on the CI in particular
This commit is contained in:
parent
c59c7d45ca
commit
4dd9f7954b
|
|
@ -2,8 +2,12 @@ package coursier
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import caseapp._
|
import caseapp._
|
||||||
import caseapp.core.{ ArgsApp, CommandsMessages }
|
import caseapp.core.{ ArgsApp, CommandMessages, CommandsMessages }
|
||||||
|
import caseapp.core.util.pascalCaseSplit
|
||||||
|
import caseapp.util.AnnotationOption
|
||||||
|
|
||||||
|
import shapeless._
|
||||||
|
import shapeless.labelled.FieldType
|
||||||
import shapeless.union.Union
|
import shapeless.union.Union
|
||||||
|
|
||||||
// Temporary, see comment in Coursier below
|
// Temporary, see comment in Coursier below
|
||||||
|
|
@ -21,10 +25,95 @@ final case class CoursierCommandHelper(
|
||||||
object CoursierCommandHelper {
|
object CoursierCommandHelper {
|
||||||
type U = Union.`'bootstrap -> Bootstrap, 'fetch -> Fetch, 'launch -> Launch, 'resolve -> Resolve, 'sparksubmit -> SparkSubmit`.T
|
type U = Union.`'bootstrap -> Bootstrap, 'fetch -> Fetch, 'launch -> Launch, 'resolve -> Resolve, 'sparksubmit -> SparkSubmit`.T
|
||||||
|
|
||||||
implicit val commandParser: CommandParser[CoursierCommandHelper] =
|
// Partially deriving these ones manually, to circumvent more-or-less random failures during auto derivation
|
||||||
CommandParser[U].map(CoursierCommandHelper(_))
|
// Only running into those with the new custom sbt launcher though :-|
|
||||||
implicit val commandsMessages: CommandsMessages[CoursierCommandHelper] =
|
|
||||||
CommandsMessages(CommandsMessages[U].messages)
|
implicit def commandParser: CommandParser[CoursierCommandHelper] =
|
||||||
|
CommandParser.ccons(
|
||||||
|
Witness('bootstrap),
|
||||||
|
AnnotationOption[CommandName, Bootstrap],
|
||||||
|
Parser[Bootstrap],
|
||||||
|
CommandParser.ccons(
|
||||||
|
Witness('fetch),
|
||||||
|
AnnotationOption[CommandName, Fetch],
|
||||||
|
Parser[Fetch],
|
||||||
|
CommandParser.ccons(
|
||||||
|
Witness('launch),
|
||||||
|
AnnotationOption[CommandName, Launch],
|
||||||
|
Parser[Launch],
|
||||||
|
CommandParser.ccons(
|
||||||
|
Witness('resolve),
|
||||||
|
AnnotationOption[CommandName, Resolve],
|
||||||
|
Parser[Resolve],
|
||||||
|
CommandParser.ccons(
|
||||||
|
Witness('sparksubmit),
|
||||||
|
AnnotationOption[CommandName, SparkSubmit],
|
||||||
|
Parser[SparkSubmit],
|
||||||
|
CommandParser.cnil
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).map(CoursierCommandHelper(_))
|
||||||
|
|
||||||
|
|
||||||
|
// Cut-n-pasted from caseapp.core.CommandsMessages.ccons, fixing the type of argsName
|
||||||
|
private def commandsMessagesCCons[K <: Symbol, H, T <: Coproduct]
|
||||||
|
(implicit
|
||||||
|
key: Witness.Aux[K],
|
||||||
|
commandName: AnnotationOption[CommandName, H],
|
||||||
|
parser: Strict[Parser[H]],
|
||||||
|
argsName: AnnotationOption[ArgsName, H],
|
||||||
|
tail: CommandsMessages[T]
|
||||||
|
): CommandsMessages[FieldType[K, H] :+: T] = {
|
||||||
|
// FIXME Duplicated in CommandParser.ccons
|
||||||
|
val name = commandName().map(_.commandName).getOrElse {
|
||||||
|
pascalCaseSplit(key.value.name.toList.takeWhile(_ != '$'))
|
||||||
|
.map(_.toLowerCase)
|
||||||
|
.mkString("-")
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandsMessages((name -> CommandMessages(
|
||||||
|
parser.value.args,
|
||||||
|
argsName().map(_.argsName)
|
||||||
|
)) +: tail.messages)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
implicit def commandsMessages: CommandsMessages[CoursierCommandHelper] =
|
||||||
|
CommandsMessages(
|
||||||
|
commandsMessagesCCons(
|
||||||
|
Witness('bootstrap),
|
||||||
|
AnnotationOption[CommandName, Bootstrap],
|
||||||
|
Parser[Bootstrap],
|
||||||
|
AnnotationOption[ArgsName, Bootstrap],
|
||||||
|
commandsMessagesCCons(
|
||||||
|
Witness('fetch),
|
||||||
|
AnnotationOption[CommandName, Fetch],
|
||||||
|
Parser[Fetch],
|
||||||
|
AnnotationOption[ArgsName, Fetch],
|
||||||
|
commandsMessagesCCons(
|
||||||
|
Witness('launch),
|
||||||
|
AnnotationOption[CommandName, Launch],
|
||||||
|
Parser[Launch],
|
||||||
|
AnnotationOption[ArgsName, Launch],
|
||||||
|
commandsMessagesCCons(
|
||||||
|
Witness('resolve),
|
||||||
|
AnnotationOption[CommandName, Resolve],
|
||||||
|
Parser[Resolve],
|
||||||
|
AnnotationOption[ArgsName, Resolve],
|
||||||
|
commandsMessagesCCons(
|
||||||
|
Witness('sparksubmit),
|
||||||
|
AnnotationOption[CommandName, SparkSubmit],
|
||||||
|
Parser[SparkSubmit],
|
||||||
|
AnnotationOption[ArgsName, SparkSubmit],
|
||||||
|
CommandsMessages.cnil
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).messages
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
object Coursier extends CommandAppOf[
|
object Coursier extends CommandAppOf[
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue