Skip to content

Mixup of Option short and long name #1284

@andreschaefer

Description

@andreschaefer

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");
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/need-triageTeam needs to triage and take a first look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions