From 155b12fbaa93b2d34c4e1cf5d883ddcca787d0ea Mon Sep 17 00:00:00 2001 From: hinerm Date: Thu, 12 Dec 2024 10:46:36 -0600 Subject: [PATCH] Ensure hints match the var key for aliased fields Jaunch config fields are entered as hints to trigger the appropriate actions. For assignment fields, there is a corresponding K:V entry in the vars. Config fields can have multiple key aliases, but regardless of which is entered we always add the first "primary" alias to the vars table. We must also register the hint matching this vars entry, otherwise the vars entry will be ignored when processing the hint and the intended function will fail. With this change, this now happens correctly. Previously we were recording the hint using the actual alias, resulting in aliases not working. Closes https://github.com/apposed/jaunch/issues/62 --- src/commonMain/kotlin/main.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/main.kt b/src/commonMain/kotlin/main.kt index 68512c8..f52d270 100644 --- a/src/commonMain/kotlin/main.kt +++ b/src/commonMain/kotlin/main.kt @@ -268,6 +268,7 @@ private fun classifyArguments( if (option.assignment == null) { // standalone option if (argVal != null) fail("Option $argKey does not accept a parameter") + hints += argKey } else { // option with value assignment val v = argVal ?: if (i < inputArgs.size) inputArgs[i++] else @@ -276,14 +277,18 @@ private fun classifyArguments( // Normalize the argument to the primary flag on the comma-separated list. // Then strip leading dashes: --class-path becomes class-path, -v becomes v, etc. var varName = option.flags.first() + // We also must record a hint to say which flags are enabled. + // This hint must match the var entry (with dividers as applicable) + val hintName = varName while (varName.startsWith("-")) varName = varName.substring(1) // Store assignment value as a variable named after the normalized argument. // E.g. if the matching supported option is `--heap,--mem=|Maximum heap size`, // and `--mem 52g` is given, it will store `"52g"` for the variable `heap`. vars[varName] = v + + hints += hintName } - hints += argKey } else { // The argument is not a Jaunch one. Save it for later. if (divider < 0) {