From 4dd9f7954b28e1bae7df29860dbfe8a95ddcfe3d Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 22 Feb 2017 22:18:30 +0100 Subject: [PATCH] Tweak some type class derivations Hopefully will address more-or-less random failures, on the CI in particular --- .../scala-2.11/coursier/cli/Coursier.scala | 99 ++++++++++++++++++- 1 file changed, 94 insertions(+), 5 deletions(-) diff --git a/cli/src/main/scala-2.11/coursier/cli/Coursier.scala b/cli/src/main/scala-2.11/coursier/cli/Coursier.scala index 1cb732438..b15dcd461 100644 --- a/cli/src/main/scala-2.11/coursier/cli/Coursier.scala +++ b/cli/src/main/scala-2.11/coursier/cli/Coursier.scala @@ -2,8 +2,12 @@ package coursier package cli 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 // Temporary, see comment in Coursier below @@ -21,10 +25,95 @@ final case class CoursierCommandHelper( object CoursierCommandHelper { type U = Union.`'bootstrap -> Bootstrap, 'fetch -> Fetch, 'launch -> Launch, 'resolve -> Resolve, 'sparksubmit -> SparkSubmit`.T - implicit val commandParser: CommandParser[CoursierCommandHelper] = - CommandParser[U].map(CoursierCommandHelper(_)) - implicit val commandsMessages: CommandsMessages[CoursierCommandHelper] = - CommandsMessages(CommandsMessages[U].messages) + // Partially deriving these ones manually, to circumvent more-or-less random failures during auto derivation + // Only running into those with the new custom sbt launcher though :-| + + 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[