mirror of
https://github.com/tadfisher/gradle2nix.git
synced 2026-03-11 04:45:23 -04:00
Update CLI interface
This commit is contained in:
@@ -13,7 +13,6 @@ dependencies {
|
||||
implementation(libs.kotlinx.coroutines.core)
|
||||
implementation(libs.okio)
|
||||
implementation(libs.serialization.json)
|
||||
implementation(libs.slf4j.api)
|
||||
runtimeOnly(libs.slf4j.simple)
|
||||
implementation(libs.xmlutil)
|
||||
|
||||
@@ -30,7 +29,10 @@ dependencies {
|
||||
application {
|
||||
mainClass.set("org.nixos.gradle2nix.MainKt")
|
||||
applicationName = "gradle2nix"
|
||||
applicationDefaultJvmArgs += "-Dorg.nixos.gradle2nix.share=@APP_HOME@/share"
|
||||
applicationDefaultJvmArgs = listOf(
|
||||
"-Dorg.nixos.gradle2nix.share=@APP_HOME@/share",
|
||||
"-Dslf4j.internal.verbosity=ERROR"
|
||||
)
|
||||
applicationDistribution
|
||||
.from(configurations.named("share"))
|
||||
.into("share")
|
||||
@@ -58,13 +60,10 @@ tasks {
|
||||
startScripts {
|
||||
doLast {
|
||||
unixScript.writeText(
|
||||
unixScript.readText()
|
||||
.replace("@APP_HOME@", "\\\"\$APP_HOME\\\"")
|
||||
.replace(Regex("DEFAULT_JVM_OPTS=\'(.*)\'")) { match ->
|
||||
"DEFAULT_JVM_OPTS=${match.groupValues[1]}"
|
||||
}
|
||||
unixScript.readText().replace("@APP_HOME@", "'\$APP_HOME'")
|
||||
)
|
||||
windowsScript.writeText(windowsScript.readText().replace("@APP_HOME@", "%APP_HOME%"))
|
||||
windowsScript.writeText(
|
||||
windowsScript.readText().replace("@APP_HOME@", "%APP_HOME%"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.github.ajalt.clikt.output.MordantHelpFormatter
|
||||
import com.github.ajalt.clikt.parameters.arguments.argument
|
||||
import com.github.ajalt.clikt.parameters.arguments.multiple
|
||||
import com.github.ajalt.clikt.parameters.options.default
|
||||
import com.github.ajalt.clikt.parameters.options.defaultLazy
|
||||
import com.github.ajalt.clikt.parameters.options.flag
|
||||
import com.github.ajalt.clikt.parameters.options.multiple
|
||||
import com.github.ajalt.clikt.parameters.options.option
|
||||
@@ -50,6 +51,43 @@ enum class LogLevel {
|
||||
class Gradle2Nix : CliktCommand(
|
||||
name = "gradle2nix"
|
||||
) {
|
||||
private val tasks: List<String> by option(
|
||||
"--task", "-t",
|
||||
metavar = "TASK",
|
||||
help = "Gradle tasks to run"
|
||||
).multiple()
|
||||
|
||||
private val projectDir: File by option(
|
||||
"--project", "-p",
|
||||
help = "Path to the project root")
|
||||
.file()
|
||||
.default(File("."), "Current directory")
|
||||
.validate { file ->
|
||||
if (!file.exists()) fail("Directory \"$file\" does not exist.")
|
||||
if (file.isFile) fail("Directory \"$file\" is a file.")
|
||||
if (!file.canRead()) fail("Directory \"$file\" is not readable.")
|
||||
if (!file.isProjectRoot()) fail("Directory \"$file\" is not a Gradle project.")
|
||||
}
|
||||
|
||||
private val outDir: File? by option(
|
||||
"--out-dir", "-o",
|
||||
metavar = "DIR",
|
||||
help = "Path to write generated files")
|
||||
.file(canBeFile = false, canBeDir = true)
|
||||
.defaultLazy("<project>") { projectDir }
|
||||
|
||||
private val lockFile: String by option(
|
||||
"--lock-file", "-l",
|
||||
metavar = "FILENAME",
|
||||
help = "Name of the generated lock file"
|
||||
).default("gradle.lock")
|
||||
|
||||
private val nixFile: String by option(
|
||||
"--nix-file", "-n",
|
||||
metavar = "FILENAME",
|
||||
help = "Name of the generated Nix file"
|
||||
).default("gradle.nix")
|
||||
|
||||
private val gradleVersion: String? by option(
|
||||
"--gradle-version", "-g",
|
||||
metavar = "VERSION",
|
||||
@@ -62,50 +100,12 @@ class Gradle2Nix : CliktCommand(
|
||||
help = "JDK home directory to use for launching Gradle (default: ${System.getProperty("java.home")})"
|
||||
).file(canBeFile = false, canBeDir = true)
|
||||
|
||||
val outDir: File? by option(
|
||||
"--out-dir", "-o",
|
||||
metavar = "DIR",
|
||||
help = "Path to write generated files (default: PROJECT-DIR)")
|
||||
.file(canBeFile = false, canBeDir = true)
|
||||
|
||||
val lockFile: String by option(
|
||||
"--lock-file", "-l",
|
||||
metavar = "FILENAME",
|
||||
help = "Name of the generated lock file"
|
||||
).default("gradle.lock")
|
||||
|
||||
val nixFile: String by option(
|
||||
"--nix-file", "-n",
|
||||
metavar = "FILENAME",
|
||||
help = "Name of the generated Nix file"
|
||||
).default("gradle.nix")
|
||||
|
||||
private val logLevel: LogLevel by option(
|
||||
"--log",
|
||||
metavar = "LEVEL",
|
||||
help = "Print messages with priority of at least LEVEL")
|
||||
help = "Print messages with this priority or higher")
|
||||
.enum<LogLevel>()
|
||||
.default(LogLevel.error)
|
||||
|
||||
private val projectDir: File by option(
|
||||
"--projectDir", "-d",
|
||||
metavar = "PROJECT-DIR",
|
||||
help = "Path to the project root (default: .)")
|
||||
.file()
|
||||
.default(File("."), "Current directory")
|
||||
.validate { file ->
|
||||
if (!file.exists()) fail("Directory \"$file\" does not exist.")
|
||||
if (file.isFile) fail("Directory \"$file\" is a file.")
|
||||
if (!file.canRead()) fail("Directory \"$file\" is not readable.")
|
||||
if (!file.isProjectRoot()) fail("Directory \"$file\" is not a Gradle project.")
|
||||
}
|
||||
|
||||
private val tasks: List<String> by option(
|
||||
"--tasks", "-t",
|
||||
metavar = "TASKS",
|
||||
help = "Gradle tasks to run"
|
||||
).multiple()
|
||||
|
||||
private val dumpEvents: Boolean by option(
|
||||
"--dump-events",
|
||||
help = "Dump Gradle event logs to the output directory",
|
||||
@@ -132,7 +132,7 @@ class Gradle2Nix : CliktCommand(
|
||||
val logger = Logger(logLevel = logLevel, stacktrace = stacktrace)
|
||||
|
||||
val appHome = System.getProperty("org.nixos.gradle2nix.share")?.let(::File)
|
||||
?: error("could not locate the /share directory in the gradle2nix installation")
|
||||
?: error("could not locate the /share directory in the gradle2nix installation: ${System.getenv("APP_HOME")}")
|
||||
val gradleHome =
|
||||
System.getenv("GRADLE_USER_HOME")?.let(::File) ?: File("${System.getProperty("user.home")}/.gradle")
|
||||
val config = Config(
|
||||
|
||||
Reference in New Issue
Block a user