combining input task with dynamic task in sbt

后端 未结 1 1922
旧巷少年郎
旧巷少年郎 2021-02-06 12:03

I\'d like to make an input task that proceed user input and generate bunch of subtasks to run. Here is the example:

import sbt._
import Keys._
import Def.Initial         


        
1条回答
  •  梦谈多话
    2021-02-06 12:41

    Trial and error method gave me the answer but non a single bit of understanding. Here it is:

    import sbt._
    import Keys._
    import Def.Initialize
    import complete.DefaultParsers._
    
    object TestBuild extends Build {
      val sampleInput = inputKey[Seq[String]]("sample dynamic input task")
      val sampleDynamic = taskKey[Seq[String]]("sample dynamic task")
    
      override lazy val settings = super.settings ++ Seq(
        sampleDynamic := Def.taskDyn {
          val sources = Seq("ab", "csd", "efda")
          sources.map(sampleTaskFor _).joinWith(_.join)
        }.value,
        sampleInput := Def.inputTaskDyn {
          val sources = spaceDelimited("").parsed
          sampleTaskAll(sources)
        }.evaluated
      )
    
      private def sampleTaskFor(source : String) : Initialize[Task[String]] = Def.task {
        source + " : " + source
      }
    
      private def sampleTaskAll(sources : Seq[String]) : Initialize[Task[Seq[String]]] = Def.taskDyn {
        sources.map(sampleTaskFor _).joinWith(_.join)
      }
    }
    

    For a reason I can not comprehend you should isolate creating multitask out of sequence of single tasks in a separate method.

    0 讨论(0)
提交回复
热议问题