Skip to content

/‑prefixed args with = misparsed as non-existing option #634

Description

@matthieugicquel

= is a valid char in a posix cli argument or filesystem paths, but clikt currently doesn't accept it and errors with "no such option".

I come from far away with this issue 🙂. My real-world situation is developing a React Native app, using pnpm's patching feature, which creates folders with =, which google prefab, called by Android Gradle Plugin without a -- before arguments, fails to handle. Prefab uses clikt.

class C : CliktCommand() {
    val x by argument()
    override fun run() = echo(x)
}

C().parse("/some/path-with=sign/foo")

→ Error: no such option /some/path-with

I've looked at the code a little and I know it's complicated as / can be a valid prefix for options. I'm probably missing some things, but it looks like ignoring unknown prefixes when trying to detect options could fix the issue without too many bad side-effects. Something like this:

     private fun isLongOptionWithEquals(prefix: String, token: String): Boolean {
         // ...
+        if (prefix !in prefixes) return false
         return context.transformToken(context, token.take(2)) !in optionsByName
     }

Happy to make a PR if it helps!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions