Repository: apple/pkl
File: pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/commands/BaseOptions.kt (Kotlin)

Code before:
          } catch (e: URISyntaxException) {
            val message = buildString {
              append("Module URI `$moduleName` has invalid syntax (${e.reason}).")
              if (e.index > -1) {
                append("\n\n")
                append(moduleName)
                append("\n")
                append(" ".repeat(e.index))
                append("^")
              }
            }
            throw CliException(message)
          }
      }

    fun RawOption.splitProps(): NullableOption<Pair<String, String>, Pair<String, String>> {
      return convert {
        val parts = it.split("=")
        if (parts.size <= 1) parts[0] to "true" else parts[0] to parts[1]
      }
    }

    fun RawOption.associateProps():
      OptionWithValues<Map<String, String>, Pair<String, String>, Pair<String, String>> {
      return splitProps().multiple().toMap()
    }
  }

  private val defaults = CliBaseOptions()

  private val output =
    arrayOf("json", "jsonnet", "pcf", "properties", "plist", "textproto", "xml", "yaml")

  val allowedModules: List<Pattern> by
    option(
        names = arrayOf("--allowed-modules"),
        help = "URI patterns that determine which modules can be loaded and evaluated."
      )
      .convert("<pattern1,pattern2>") { Pattern.compile(it) }
      .splitAll(",")

  val allowedResources: List<Pattern> by
    option(
        names = arrayOf("--allowed-resources"),
        help = "URI patterns that determine which external resources can be read."
      )
      .convert("<pattern1,pattern2>") { Pattern.compile(it) }
      .splitAll(",")

  val rootDir: Path? by
    option(

Review comment (suggestion):
I'd inline at least once (if not entirely on the `associateProps` call site:
```suggestion
    fun RawOption.associateProps():
      OptionWithValues<Map<String, String>, Pair<String, String>, Pair<String, String>> {
      return convert {
        val parts = it.split("=")
        parts[0] to (parts.getOrNull(1) ?: "true")
      }.multiple().toMap()
    }
```

Code after:
          } catch (e: URISyntaxException) {
            val message = buildString {
              append("Module URI `$moduleName` has invalid syntax (${e.reason}).")
              if (e.index > -1) {
                append("\n\n")
                append(moduleName)
                append("\n")
                append(" ".repeat(e.index))
                append("^")
              }
            }
            throw CliException(message)
          }
      }

    fun RawOption.associateProps():
      OptionWithValues<Map<String, String>, Pair<String, String>, Pair<String, String>> {
      return convert {
          val parts = it.split("=")
          if (parts.size <= 1) parts[0] to "true" else parts[0] to parts[1]
        }
        .multiple()
        .toMap()
    }
  }

  private val defaults = CliBaseOptions()

  private val output =
    arrayOf("json", "jsonnet", "pcf", "properties", "plist", "textproto", "xml", "yaml")

  val allowedModules: List<Pattern> by
    option(
        names = arrayOf("--allowed-modules"),
        help = "URI patterns that determine which modules can be loaded and evaluated."
      )
      .convert("<pattern1,pattern2>") { Pattern.compile(it) }
      .splitAll(",")

  val allowedResources: List<Pattern> by
    option(
        names = arrayOf("--allowed-resources"),
        help = "URI patterns that determine which external resources can be read."
      )
      .convert("<pattern1,pattern2>") { Pattern.compile(it) }
      .splitAll(",")

  val rootDir: Path? by
    option(
        names = arrayOf("--root-dir"),
        help =