Kotlin/kotlinx-cli

Custom Choice with toString method gives confusing message

westonal opened this issue · 0 comments

This test passes when it should not. Note the message [l, s, p]. l is provided.

    @Test
    fun testEnumChoiceWithCustomToString() {
        val argParser = ArgParser("testParser").avoidProcessExit()
        val sources by argParser.option(ArgType.Choice<DataSourceEnum> { it.name[0].toString().lowercase() },
            "sources", "s", "Data sources")
        val exception = assertFailsWith<IllegalStateException> {
            argParser.parse(arrayOf("-s", "l"))
        }
        assertTrue("Option sources is expected to be one of [l, s, p]. l is provided." in exception.message!!)
    }

Given I have supplied a toString, I wasn't expecting to have to supply the reverse toVariant.

I think this is a bug, the default toVariant search should use the supplied toString, not the enum's value's name