How to combine input parser with fullRunInputTask?

In my build.sbt file, I want to have a task with input parameters that calls the method mainin my code, but before calling the method I would like to have the parameters analyzed .

This is the definition of InputKey:

val clearDatabase = inputKey[Unit]("Clear database, arguments:  endpoint user password")

The analyzer that I would like to use:

val databaseTaskParser = sbt.Def.spaceDelimited("endpoint username password").map(_.toList).map {
  case List(endpoint) => (endpoint, "", "")
  case List(endpoint, username, password) => (endpoint, username, password)
  case _ =>
    sys.error("Supported arguments: \"endpoint\" or \"endpoint username password\"")
}

And then I know that to pass the input arguments to the main method I need to use a parameter fullRunInputTaskparameterized with the InputKey above:

fullRunInputTask(clearDatabase, Compile, "my.code.ClearDatabaseTask")

Now, how can I combine the call with fullRunInputTaskusing databaseTaskParser(to display an error when the wrong set of parameters is set) even before the method is calledmain

+4
source share
1

, .

, runTask fullRunInputTask, , . evaluate, InputTask inputKey.

, :

clearDatabase := Def.inputTaskDyn {
  runTask(Compile, "my.code.ClearDatabaseTask", databaseTaskParser.parsed:_*)
}.evaluated

, , , , . :

val databaseTaskParser = sbt.Def.spaceDelimited("endpoint username password").map(_.toList).map {
  case args if List(1, 3).contains(args.length) => args.padTo(3, "")
  case _ =>
        sys.error("Supported arguments: \"endpoint\" or \"endpoint username password\"")
}

: sbt clearDatabase , , main my.code.ClearDatabaseTask, , , .

+1

Source: https://habr.com/ru/post/1676754/


All Articles