spring-shell icon indicating copy to clipboard operation
spring-shell copied to clipboard

Mixup of Option short and long name

Open andreschaefer opened this issue 3 weeks ago • 1 comments

There is a mixup of @Option shortName mapping when there is a specific shortName defined by an Option but another Options longName starts with the same letter. There seems to be some kind of default/fallback logic that ignores explicit mapping on other parameters.

Example Command

@Component
class Demo {
    @Command(name = "demo")
    String demo(
            @Option(longName = "aWrong") String aWrong,
            @Option(longName = "intendedA", shortName = 'a') String aIntended
    ) {
        return "aWrong=%s intendedA=%s".formatted(aWrong, aIntended);
    }
}

Test

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.shell.test.ShellTestClient;
import org.springframework.shell.test.autoconfigure.ShellTest;

import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
import static org.springframework.shell.test.ShellAssertions.assertThat;

@ShellTest
@SpringBootTest(
        webEnvironment = NONE,
        properties = {"spring.shell.interactive.enabled=false"})
class ShortNameProblemTest {

    @Autowired
    ShellTestClient client;

    @Test
    void shouldPrint_correctValues() throws Exception {
        var screen = client.sendCommand("demo -a intended");
        assertThat(screen).containsText("aWrong= intendedA=intended");
    }

}

andreschaefer avatar Jan 07 '26 15:01 andreschaefer