add version info output
This commit is contained in:
parent
0af6f8ebc2
commit
8d9de5517a
6 changed files with 49 additions and 13 deletions
17
build.gradle
17
build.gradle
|
@ -234,3 +234,20 @@ publishing {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create version file to allow Kotlin code to print own version - see https://stackoverflow.com/questions/33020069/how-to-get-version-attribute-from-a-gradle-build-to-be-included-in-runtime-swing
|
||||
tasks.register('createVersion') {
|
||||
dependsOn processResources
|
||||
doLast {
|
||||
def version = project.version.toString() + " (" + Instant.now().toString().split("\\.")[0] + ")"
|
||||
def fileName = "src/main/resources/version.txt"
|
||||
def file = new File(fileName)
|
||||
file.write(version)
|
||||
println "Created file: " + fileName
|
||||
}
|
||||
}
|
||||
|
||||
classes {
|
||||
dependsOn createVersion
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.domaindrivenarchitecture.provs.desktop.domain.DesktopConfig
|
|||
import org.domaindrivenarchitecture.provs.desktop.domain.provisionDesktopCommand
|
||||
import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig
|
||||
import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance
|
||||
import org.domaindrivenarchitecture.provs.framework.core.cli.printProvsVersion
|
||||
import org.domaindrivenarchitecture.provs.framework.core.cli.quit
|
||||
import java.io.FileNotFoundException
|
||||
import java.nio.file.Files
|
||||
|
@ -17,6 +18,8 @@ import kotlin.system.exitProcess
|
|||
*/
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
printProvsVersion()
|
||||
|
||||
val cmd = CliArgumentsParser("provs-desktop.jar subcommand target").parseCommand(args)
|
||||
if (!cmd.isValid()) {
|
||||
println("Arguments are not valid, pls try option -h for help.")
|
||||
|
@ -31,12 +34,12 @@ fun main(args: Array<String>) {
|
|||
val configFileName = cmd.configFile?.fileName ?: defaultConfigFileName
|
||||
try {
|
||||
getConfig(configFileName)
|
||||
} catch (e: SerializationException) {
|
||||
} catch (_: SerializationException) {
|
||||
println(
|
||||
"Error: File \"${configFileName}\" has an invalid format and or invalid data."
|
||||
)
|
||||
null
|
||||
} catch (e: FileNotFoundException) {
|
||||
} catch (_: FileNotFoundException) {
|
||||
println(
|
||||
"Error: File\u001b[31m $configFileName \u001b[0m was not found.\n" +
|
||||
"Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m $configFileName \u001B[0m " +
|
||||
|
|
|
@ -35,6 +35,20 @@ fun createProvInstance(targetCommand: TargetCliCommand): Prov {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper for exitProcess, which allows e.g. mocking for test purposes
|
||||
*/
|
||||
fun quit(status: Int): Nothing {
|
||||
exitProcess(status)
|
||||
}
|
||||
|
||||
|
||||
fun printProvsVersion() {
|
||||
val version = object {}.javaClass.getResource("/version.txt")?.readText()?.trim()
|
||||
println("Provs version: $version")
|
||||
}
|
||||
|
||||
|
||||
internal fun createRemoteProvInstance(
|
||||
target: TargetCliCommand.RemoteTarget?,
|
||||
password: Secret? = null
|
||||
|
@ -52,11 +66,3 @@ internal fun createRemoteProvInstance(
|
|||
internal fun getPasswordToConfigureSudoWithoutPassword(): Secret {
|
||||
return PromptSecretSource("password to configure sudo without password.").secret()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper for exitProcess, which allows e.g. mocking for test purposes
|
||||
*/
|
||||
fun quit(status: Int): Nothing {
|
||||
exitProcess(status)
|
||||
}
|
|
@ -2,6 +2,7 @@ package org.domaindrivenarchitecture.provs.server.application
|
|||
|
||||
import org.domaindrivenarchitecture.provs.configuration.application.ensureSudoWithoutPassword
|
||||
import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance
|
||||
import org.domaindrivenarchitecture.provs.framework.core.cli.printProvsVersion
|
||||
import org.domaindrivenarchitecture.provs.framework.core.cli.quit
|
||||
import org.domaindrivenarchitecture.provs.server.domain.ServerType
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand
|
||||
|
@ -17,6 +18,8 @@ import kotlin.system.exitProcess
|
|||
*/
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
printProvsVersion()
|
||||
|
||||
val checkedArgs = if (args.isEmpty()) arrayOf("-h") else args
|
||||
|
||||
// validate subcommand
|
||||
|
|
1
src/main/resources/version.txt
Normal file
1
src/main/resources/version.txt
Normal file
|
@ -0,0 +1 @@
|
|||
0.39.3-SNAPSHOT (2024-12-11T20:58:26)
|
|
@ -15,7 +15,7 @@ import org.domaindrivenarchitecture.provs.framework.core.cli.quit
|
|||
import org.domaindrivenarchitecture.provs.framework.core.processors.DummyProcessor
|
||||
import org.domaindrivenarchitecture.provs.test.setRootLoggingLevel
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
|
@ -116,7 +116,10 @@ internal class ApplicationKtTest {
|
|||
|
||||
val expectedOutput =
|
||||
"Error: File\u001B[31m idontexist.yaml \u001B[0m was not found.Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m idontexist.yaml \u001B[0m and change the content according to your needs.No suitable config found."
|
||||
assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", ""))
|
||||
assertTrue(
|
||||
outContent.toString().replace("\r", "").replace("\n", "").contains(expectedOutput),
|
||||
"$expectedOutput\nnot found in:\n$outContent"
|
||||
)
|
||||
|
||||
verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any()) }
|
||||
|
||||
|
@ -150,7 +153,10 @@ internal class ApplicationKtTest {
|
|||
|
||||
val expectedOutput =
|
||||
"Error: File \"src/test/resources/invalid-desktop-config.yaml\" has an invalid format and or invalid data.No suitable config found."
|
||||
assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", ""))
|
||||
assertTrue(
|
||||
outContent.toString().replace("\r", "").replace("\n", "").contains(expectedOutput),
|
||||
"$expectedOutput\nnot found in:\n$outContent"
|
||||
)
|
||||
|
||||
verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any()) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue