Add command group

This commit is contained in:
2025-10-01 18:31:43 +02:00
parent ea43453f07
commit 4fd033ee82
7 changed files with 61 additions and 30 deletions

View File

@@ -10,7 +10,7 @@ import os.Path
class LongnailSchedCommand extends MySubcommand("scheduleISAX") with CoreSelection { class LongnailSchedCommand extends MySubcommand("scheduleISAX") with CoreSelection {
val inputFiles: ScallopOption[List[Path]] = trailArg[List[Path]]("inputFiles", group = mainGroup) val inputFiles: ScallopOption[List[Path]] = trailArg[List[Path]]("inputFiles", group = mainGroup)
val outputDirectory: ScallopOption[Path] = opt[Path](group = mainGroup) val outputDirectory: ScallopOption[Path] = opt[Path](group = mainGroup)
val schedParams: SchedulingParameters = addOptionGroup(new SchedulingParameters) val schedParams: SchedulingParameters = addConfigElement(new SchedulingParameters)
validateOSPathIsDirectory(outputDirectory) validateOSPathIsDirectory(outputDirectory)

View File

@@ -1,6 +1,6 @@
package com.minres.tgc.hammer.cli 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 com.minres.tgc.hammer.tasks.Task
import org.rogach.scallop.{ScallopOption, ScallopOptionGroup, Subcommand, Util} 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 getRequiredTasks: Seq[Task]
def addOptions(options: Seq[BaseOption[?]]): Unit = { def addConfigElement[T <: ConfigElement](elem: T): T = {
options.foreach(_.init(this, null)) elem.init(this, null)
} elem
def addOptionGroup[T <: OptionGroup](group: T): T = {
group.init(this)
group
} }
def validateOSPathIsDirectory(pathOption: ScallopOption[os.Path]): Unit = addValidation { def validateOSPathIsDirectory(pathOption: ScallopOption[os.Path]): Unit = addValidation {

View File

@@ -5,10 +5,12 @@ import os.Shellable
import scala.compiletime.uninitialized 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] protected def createScallop(conf: ScallopConf, group: ScallopOptionGroup): ScallopOption[T]
private var scallop: ScallopOption[T] = uninitialized 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 get: T = scallop()
def apply: T = get def apply: T = get

View File

@@ -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))
}
}

View File

@@ -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
}

View File

@@ -1,27 +1,20 @@
package com.minres.tgc.hammer.options package com.minres.tgc.hammer.options
import org.rogach.scallop.{ScallopConf, ValueConverter} import org.rogach.scallop.{ScallopConf, ScallopOptionGroup, ValueConverter}
import os.Shellable import os.Shellable
import scala.collection.mutable import scala.collection.mutable
export com.minres.tgc.hammer.cli.osPathConverter export com.minres.tgc.hammer.cli.osPathConverter
trait OptionGroup { trait BaseGroup extends ConfigElement {
def name: String protected val options = mutable.ListBuffer[ConfigElement]()
private val options = mutable.ListBuffer[BaseOption[?]]() protected def add[T <: ConfigElement](option: T): T = {
protected def add[T <: BaseOption[?]](option: T): T = {
options += option options += option
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 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)) 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 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)) 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))
}
}

View File

@@ -7,15 +7,18 @@ import org.rogach.scallop.*
class SchedulingParameters extends OptionGroup { class SchedulingParameters extends OptionGroup {
override def name: String = "Longnail Scheduling Args" override def name: String = "Longnail Scheduling Args"
value[Int](cliName = "maxLoopUnrollFactor", toolName = "max-unroll-factor") add(new CommandGroup("schedule-lil") {
valueS[Int](name = "schedulingTimeout") valueS[Int](name = "schedulingTimeout")
value[Int](cliName = "schedulingRefineTimeout", toolName = "schedRefineTimeout") value[Int](cliName = "schedulingRefineTimeout", toolName = "schedRefineTimeout")
value[Path](cliName = "schedulingKconf", toolName = "solSelKconfPath") 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")) 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")) choice(Seq("CBC", "GLPK", "SCIP", "HIGHS", "GUROBI", "CPLEX", "XPRESS", "COPT"), cliName = "ilpSolver", toolName = "solver", default = Some("CBC"))
toggle(cliName = "verboseSched", toolName = "verbose") toggle(cliName = "verboseSched", toolName = "verbose")
valueS[Path](name = "opTyLibrary") valueS[Path](name = "opTyLibrary")
value[Int](cliName = "clockPeriod", toolName = "clockTime") value[Int](cliName = "clockPeriod", toolName = "clockTime")
value[Path](cliName = "cellLibrary", toolName = "library") value[Path](cliName = "cellLibrary", toolName = "library")
})
value[Int](cliName = "maxLoopUnrollFactor", toolName = "max-unroll-factor")
value[Path](cliName = "schedulingMLIR", toolName = "o")
} }