Skip to content

Commit

Permalink
Read all intended config files in correct order
Browse files Browse the repository at this point in the history
The intended order is:
- jaunch.toml
- jaunch-<os>.toml
- jaunch-<os>-<arch>.toml
- launcher.toml
- launcher-<os>.toml
- launcher-<os>-<arch>.toml

Since later configuration details are *prepended* to earlier ones,
which lets launcher- and platform-specific settings take precedence.
  • Loading branch information
ctrueden committed Feb 8, 2024
1 parent b4b1521 commit fbb631c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/commonMain/kotlin/Jaunch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,28 @@ fun main(args: Array<String>) {
error("Jaunch config directory not found. Please place config in one of: $configDirs")
debug("configDir -> ", configDir)

// Load the configuration from the TOML file(s).
var config = readConfig(configDir / "jaunch.toml")
config += readConfig(configDir / "jaunch-$$OS_NAME.toml")
config += readConfig(configDir / "jaunch-$$OS_NAME-$CPU_ARCH.toml")
// Make a list of relevant configuration files to read.
val osName = OS_NAME.lowercase()
val cpuArch = CPU_ARCH.lowercase()
var config = JaunchConfig()
val configFiles = mutableListOf(
configDir / "jaunch.toml",
configDir / "jaunch-$osName.toml",
configDir / "jaunch-$osName-$cpuArch.toml",
)
if (exeFile != null) {
// Parse and merge the app-specific TOML file(s) as well.
// Include the app-specific config file(s) as well.
val index = configFiles.size
var fileName = exeFile.base.name
while (true) {
config += readConfig(configDir / "$fileName.toml")
configFiles.add(index, configDir / "$fileName.toml")
val dash = fileName.lastIndexOf("-")
if (dash < 0) break
fileName = fileName.substring(0, dash)
}
}
// Read and merge all the config files.
for (configFile in configFiles) config += readConfig(configFile)

val programName = config.programName ?: exeFile?.base?.name ?: "Jaunch"
debug("programName -> ", programName)
Expand Down

0 comments on commit fbb631c

Please sign in to comment.