mirror of
https://github.com/Anvilcraft/modpacktools
synced 2024-06-10 22:49:26 +02:00
AbsractCommand uses property delegate for arguments instead of function now
This commit is contained in:
parent
dcc36e7ebf
commit
3fbd93a519
|
@ -6,7 +6,7 @@ import net.sourceforge.argparse4j.inf.ArgumentParser
|
||||||
/**
|
/**
|
||||||
* an implementation of [ICommand] meant to reduce boilerplate.
|
* an implementation of [ICommand] meant to reduce boilerplate.
|
||||||
* this automatically creates a base [ArgumentParser]
|
* this automatically creates a base [ArgumentParser]
|
||||||
* with the [helpMessage] as description and then applies [addArgs] to it
|
* with the [helpMessage] as description which can be modified by using [argParser]
|
||||||
* and uses [displayName] as the name for the command in the help message.
|
* and uses [displayName] as the name for the command in the help message.
|
||||||
*
|
*
|
||||||
* the [name] of the command will be a converted version of the [displayName] by default
|
* the [name] of the command will be a converted version of the [displayName] by default
|
||||||
|
@ -21,18 +21,12 @@ constructor(
|
||||||
val displayName: String,
|
val displayName: String,
|
||||||
override val name: String = displayName.toLowerCase().replace(' ', '_')
|
override val name: String = displayName.toLowerCase().replace(' ', '_')
|
||||||
) : ICommand {
|
) : ICommand {
|
||||||
override val parser: ArgumentParser by lazy {
|
protected fun argParser(block: ArgumentParser.() -> Unit) = lazy {
|
||||||
ArgumentParsers.newFor(displayName)
|
ArgumentParsers.newFor(this.displayName)
|
||||||
.build()
|
.build()
|
||||||
.description(helpMessage)
|
.description(this.helpMessage)
|
||||||
.apply {addArgs()}
|
.apply(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
override val parser: ArgumentParser by argParser {}
|
||||||
* This will be called to add arguments to the [ArgumentParser] of this command.
|
|
||||||
* override this to add arguments.
|
|
||||||
*
|
|
||||||
* @receiver the [ArgumentParser] to add the args to
|
|
||||||
*/
|
|
||||||
protected open fun ArgumentParser.addArgs() {}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import ley.anvil.modpacktools.util.downloadFiles
|
||||||
import ley.anvil.modpacktools.util.fPrintln
|
import ley.anvil.modpacktools.util.fPrintln
|
||||||
import ley.anvil.modpacktools.util.toZip
|
import ley.anvil.modpacktools.util.toZip
|
||||||
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
||||||
import net.sourceforge.argparse4j.inf.ArgumentParser
|
|
||||||
import net.sourceforge.argparse4j.inf.Namespace
|
import net.sourceforge.argparse4j.inf.Namespace
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -32,7 +31,7 @@ object BuildTwitch : AbstractCommand("BuildTwitch") {
|
||||||
private val tmp: File by lazy {File(tempDir, "twitch")}
|
private val tmp: File by lazy {File(tempDir, "twitch")}
|
||||||
private val downloadDir by lazy {File(tempDir, "download")}
|
private val downloadDir by lazy {File(tempDir, "download")}
|
||||||
|
|
||||||
override fun ArgumentParser.addArgs() {
|
override val parser by argParser {
|
||||||
arg("-a", "--all") {
|
arg("-a", "--all") {
|
||||||
help("Downloads all relations instead of just required ones")
|
help("Downloads all relations instead of just required ones")
|
||||||
action(storeTrue())
|
action(storeTrue())
|
||||||
|
|
|
@ -14,7 +14,6 @@ import ley.anvil.modpacktools.util.fPrintln
|
||||||
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
||||||
import net.sourceforge.argparse4j.impl.type.CaseInsensitiveEnumNameArgumentType
|
import net.sourceforge.argparse4j.impl.type.CaseInsensitiveEnumNameArgumentType
|
||||||
import net.sourceforge.argparse4j.impl.type.FileArgumentType
|
import net.sourceforge.argparse4j.impl.type.FileArgumentType
|
||||||
import net.sourceforge.argparse4j.inf.ArgumentParser
|
|
||||||
import net.sourceforge.argparse4j.inf.Namespace
|
import net.sourceforge.argparse4j.inf.Namespace
|
||||||
import org.apache.commons.csv.CSVFormat
|
import org.apache.commons.csv.CSVFormat
|
||||||
import org.apache.commons.csv.CSVPrinter
|
import org.apache.commons.csv.CSVPrinter
|
||||||
|
@ -28,7 +27,7 @@ import java.util.Comparator.comparing
|
||||||
object CreateModlist : AbstractCommand("CreateModlist") {
|
object CreateModlist : AbstractCommand("CreateModlist") {
|
||||||
override val helpMessage: String = "This creates a modlist either as html or csv file."
|
override val helpMessage: String = "This creates a modlist either as html or csv file."
|
||||||
|
|
||||||
override fun ArgumentParser.addArgs() {
|
override val parser by argParser {
|
||||||
arg("type") {
|
arg("type") {
|
||||||
type(CaseInsensitiveEnumNameArgumentType(Format::class.java))
|
type(CaseInsensitiveEnumNameArgumentType(Format::class.java))
|
||||||
help("What format the mod list should be made in")
|
help("What format the mod list should be made in")
|
||||||
|
|
|
@ -12,7 +12,6 @@ import ley.anvil.modpacktools.util.downloadFiles
|
||||||
import ley.anvil.modpacktools.util.fPrintln
|
import ley.anvil.modpacktools.util.fPrintln
|
||||||
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
||||||
import net.sourceforge.argparse4j.impl.type.FileArgumentType
|
import net.sourceforge.argparse4j.impl.type.FileArgumentType
|
||||||
import net.sourceforge.argparse4j.inf.ArgumentParser
|
|
||||||
import net.sourceforge.argparse4j.inf.Namespace
|
import net.sourceforge.argparse4j.inf.Namespace
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
@ -20,7 +19,7 @@ import java.io.File
|
||||||
object DownloadMods : AbstractCommand("DownloadMods") {
|
object DownloadMods : AbstractCommand("DownloadMods") {
|
||||||
override val helpMessage: String = "Downloads all mods."
|
override val helpMessage: String = "Downloads all mods."
|
||||||
|
|
||||||
override fun ArgumentParser.addArgs() {
|
override val parser by argParser {
|
||||||
arg("dir") {
|
arg("dir") {
|
||||||
type(FileArgumentType().verifyCanCreate())
|
type(FileArgumentType().verifyCanCreate())
|
||||||
help("the directory to download the mods to")
|
help("the directory to download the mods to")
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.io.FileWriter
|
||||||
object Import : AbstractCommand("Import") {
|
object Import : AbstractCommand("Import") {
|
||||||
override val helpMessage: String = "Converts a given manifest file to a modpackjson file"
|
override val helpMessage: String = "Converts a given manifest file to a modpackjson file"
|
||||||
|
|
||||||
override fun ArgumentParser.addArgs() {
|
override val parser: ArgumentParser by argParser {
|
||||||
arg("manifest") {
|
arg("manifest") {
|
||||||
help("the manifest file to import")
|
help("the manifest file to import")
|
||||||
type(FileArgumentType().verifyIsFile())
|
type(FileArgumentType().verifyIsFile())
|
||||||
|
|
|
@ -15,7 +15,7 @@ import net.sourceforge.argparse4j.inf.Namespace
|
||||||
object ListRelations : AbstractCommand("ListRelations") {
|
object ListRelations : AbstractCommand("ListRelations") {
|
||||||
override val helpMessage: String = "Lists the relations of this mod pack"
|
override val helpMessage: String = "Lists the relations of this mod pack"
|
||||||
|
|
||||||
override fun ArgumentParser.addArgs() {
|
override val parser: ArgumentParser by argParser {
|
||||||
arg("-c", "--csv") {
|
arg("-c", "--csv") {
|
||||||
help("Doesn't format as a table but instead as csv (separated by ;)")
|
help("Doesn't format as a table but instead as csv (separated by ;)")
|
||||||
action(storeTrue())
|
action(storeTrue())
|
||||||
|
|
Loading…
Reference in a new issue