Skip to content

Commit

Permalink
Ensure hints match the var key for aliased fields
Browse files Browse the repository at this point in the history
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 #62
  • Loading branch information
hinerm committed Dec 12, 2024
1 parent 1bd0934 commit 155b12f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/commonMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=<max>|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) {
Expand Down

0 comments on commit 155b12f

Please sign in to comment.