Add command group
This commit is contained in:
@@ -10,7 +10,7 @@ import os.Path
|
||||
class LongnailSchedCommand extends MySubcommand("scheduleISAX") with CoreSelection {
|
||||
val inputFiles: ScallopOption[List[Path]] = trailArg[List[Path]]("inputFiles", group = mainGroup)
|
||||
val outputDirectory: ScallopOption[Path] = opt[Path](group = mainGroup)
|
||||
val schedParams: SchedulingParameters = addOptionGroup(new SchedulingParameters)
|
||||
val schedParams: SchedulingParameters = addConfigElement(new SchedulingParameters)
|
||||
|
||||
validateOSPathIsDirectory(outputDirectory)
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.minres.tgc.hammer.cli
|
||||
|
||||
import com.minres.tgc.hammer.options.{BaseOption, OptionGroup}
|
||||
import com.minres.tgc.hammer.options.{BaseOption, ConfigElement, OptionGroup}
|
||||
import com.minres.tgc.hammer.tasks.Task
|
||||
import org.rogach.scallop.{ScallopOption, ScallopOptionGroup, Subcommand, Util}
|
||||
|
||||
@@ -11,12 +11,9 @@ abstract class MySubcommand(name: String) extends Subcommand(name) {
|
||||
|
||||
def getRequiredTasks: Seq[Task]
|
||||
|
||||
def addOptions(options: Seq[BaseOption[?]]): Unit = {
|
||||
options.foreach(_.init(this, null))
|
||||
}
|
||||
def addOptionGroup[T <: OptionGroup](group: T): T = {
|
||||
group.init(this)
|
||||
group
|
||||
def addConfigElement[T <: ConfigElement](elem: T): T = {
|
||||
elem.init(this, null)
|
||||
elem
|
||||
}
|
||||
|
||||
def validateOSPathIsDirectory(pathOption: ScallopOption[os.Path]): Unit = addValidation {
|
||||
|
@@ -5,10 +5,12 @@ import os.Shellable
|
||||
|
||||
import scala.compiletime.uninitialized
|
||||
|
||||
trait BaseOption[T](using conv: ValueConverter[T]) {
|
||||
trait BaseOption[T](using conv: ValueConverter[T]) extends ConfigElement {
|
||||
protected def createScallop(conf: ScallopConf, group: ScallopOptionGroup): ScallopOption[T]
|
||||
private var scallop: ScallopOption[T] = uninitialized
|
||||
def init(scallopConf: ScallopConf, group: ScallopOptionGroup): Unit = scallop = createScallop(scallopConf, group)
|
||||
def init(scallopConf: ScallopConf, group: ScallopOptionGroup): Unit = {
|
||||
scallop = createScallop(scallopConf, group)
|
||||
}
|
||||
|
||||
def get: T = scallop()
|
||||
def apply: T = get
|
||||
|
@@ -0,0 +1,15 @@
|
||||
package com.minres.tgc.hammer.options
|
||||
|
||||
import org.rogach.scallop.{ScallopConf, ScallopOptionGroup}
|
||||
import os.Shellable
|
||||
|
||||
class CommandGroup(name: String) extends BaseGroup {
|
||||
override def getToolParameters: Seq[Shellable] = {
|
||||
val sub = options.toSeq.flatMap(_.getToolParameters)
|
||||
Seq(s"""$name="${sub.mkString(" ")}"""")
|
||||
}
|
||||
|
||||
override def init(scallopConf: ScallopConf, group: ScallopOptionGroup): Unit = {
|
||||
options.foreach(_.init(scallopConf, group))
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
package com.minres.tgc.hammer.options
|
||||
|
||||
import org.rogach.scallop.{ScallopConf, ScallopOptionGroup}
|
||||
import os.Shellable
|
||||
|
||||
trait ConfigElement {
|
||||
def getToolParameters: Seq[Shellable]
|
||||
|
||||
def init(scallopConf: ScallopConf, group: ScallopOptionGroup): Unit
|
||||
}
|
@@ -1,27 +1,20 @@
|
||||
package com.minres.tgc.hammer.options
|
||||
|
||||
|
||||
import org.rogach.scallop.{ScallopConf, ValueConverter}
|
||||
import org.rogach.scallop.{ScallopConf, ScallopOptionGroup, ValueConverter}
|
||||
import os.Shellable
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
export com.minres.tgc.hammer.cli.osPathConverter
|
||||
|
||||
trait OptionGroup {
|
||||
def name: String
|
||||
private val options = mutable.ListBuffer[BaseOption[?]]()
|
||||
protected def add[T <: BaseOption[?]](option: T): T = {
|
||||
trait BaseGroup extends ConfigElement {
|
||||
protected val options = mutable.ListBuffer[ConfigElement]()
|
||||
protected def add[T <: ConfigElement](option: T): T = {
|
||||
options += option
|
||||
option
|
||||
}
|
||||
|
||||
def getToolParameters: Seq[Shellable] = options.toSeq.flatMap(_.getToolParameters)
|
||||
|
||||
def init(scallopConf: ScallopConf): Unit = {
|
||||
val group = scallopConf.group(name)
|
||||
options.foreach(_.init(scallopConf, group))
|
||||
}
|
||||
def value[T](cliName: String, toolName: String, descr: String = "", default: => Option[T] = None, required: Boolean = false, cliShort: Char = '\u0000')(using conv: ValueConverter[T]): ValueOption[T] = add(ValueOption(cliName, toolName, descr, default, required, cliShort))
|
||||
def valueS[T](name: String, descr: String = "", default: => Option[T] = None, required: Boolean = false, cliShort: Char = '\u0000')(using conv: ValueConverter[T]): ValueOption[T] = add(ValueOption(name, name, descr, default, required, cliShort))
|
||||
|
||||
@@ -36,3 +29,14 @@ trait OptionGroup {
|
||||
def toggle(cliName: String, toolName: String, descr: String = "", default: => Option[Boolean] = None, required: Boolean = false, cliShort: Char = '\u0000'): ToggleOption = add(ToggleOption(cliName, toolName, descr, default, required, cliShort))
|
||||
def toggleS(name: String, descr: String = "", default: => Option[Boolean] = None, required: Boolean = false, cliShort: Char = '\u0000'): ToggleOption = add(ToggleOption(name, name, descr, default, required, cliShort))
|
||||
}
|
||||
|
||||
trait OptionGroup extends BaseGroup {
|
||||
def name: String
|
||||
|
||||
override def getToolParameters: Seq[Shellable] = options.toSeq.flatMap(_.getToolParameters)
|
||||
|
||||
def init(scallopConf: ScallopConf, g: ScallopOptionGroup): Unit = {
|
||||
val group = scallopConf.group(name)
|
||||
options.foreach(_.init(scallopConf, group))
|
||||
}
|
||||
}
|
||||
|
@@ -7,15 +7,18 @@ import org.rogach.scallop.*
|
||||
class SchedulingParameters extends OptionGroup {
|
||||
override def name: String = "Longnail Scheduling Args"
|
||||
|
||||
add(new CommandGroup("schedule-lil") {
|
||||
valueS[Int](name = "schedulingTimeout")
|
||||
value[Int](cliName = "schedulingRefineTimeout", toolName = "schedRefineTimeout")
|
||||
value[Path](cliName = "schedulingKconf", toolName = "solSelKconfPath")
|
||||
choiceS(Seq("LEGACY", "MS", "PAMS", "PARAMS", "MI_MS", "MI_PAMS", "MI_PARAMS"), name = "schedulingAlgo", default = Some("LEGACY"))
|
||||
choice(Seq("CBC", "GLPK", "SCIP", "HIGHS", "GUROBI", "CPLEX", "XPRESS", "COPT"), cliName = "ilpSolver", toolName = "solver", default = Some("CBC"))
|
||||
toggle(cliName = "verboseSched", toolName = "verbose")
|
||||
valueS[Path](name = "opTyLibrary")
|
||||
value[Int](cliName = "clockPeriod", toolName = "clockTime")
|
||||
value[Path](cliName = "cellLibrary", toolName = "library")
|
||||
})
|
||||
|
||||
value[Int](cliName = "maxLoopUnrollFactor", toolName = "max-unroll-factor")
|
||||
valueS[Int](name = "schedulingTimeout")
|
||||
value[Int](cliName = "schedulingRefineTimeout", toolName = "schedRefineTimeout")
|
||||
value[Path](cliName = "schedulingKconf", toolName = "solSelKconfPath")
|
||||
value[Path](cliName = "schedulingMLIR", toolName = "o")
|
||||
choiceS(Seq("LEGACY", "MS", "PAMS", "PARAMS", "MI_MS", "MI_PAMS", "MI_PARAMS"), name = "schedulingAlgo", default = Some("LEGACY"))
|
||||
choice(Seq("CBC", "GLPK", "SCIP", "HIGHS", "GUROBI", "CPLEX", "XPRESS", "COPT"), cliName = "ilpSolver", toolName = "solver", default = Some("CBC"))
|
||||
toggle(cliName = "verboseSched", toolName = "verbose")
|
||||
valueS[Path](name = "opTyLibrary")
|
||||
value[Int](cliName = "clockPeriod", toolName = "clockTime")
|
||||
value[Path](cliName = "cellLibrary", toolName = "library")
|
||||
}
|
||||
|
Reference in New Issue
Block a user