Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commands fail in 4.0 if no short name or long name are specified #1261

@ThomasVitale

Description

@ThomasVitale

When upgrading to Spring Shell 4.0, all annotated command options that don't have a short name or long name specified fail the application initialisation.

If that change was intentional, it would be great to highlight it in the migration guide as a breaking change and update the JavaDocs as the @Option annotation states that those two arguments are optional.

Still, it would be great to restore the previous behaviour where the Java property name was used as the long name by default. That would be in line with other Spring projects like Spring MVC, where the @RequestParam doesn't require specifying a name if it matches the Java property name.

A command definition like the following with Spring Shell 3.4:

    @Command(name = "test", description = "Test command.")
    public void build(
        @Option(description = "Some option.") String myOption,
    ) {
        ...
    }

would need to change to the following in 4.0:

    @Command(name = "test", description = "Test command.")
    public void build(
        @Option(description = "Some option.",  longName = "myOption") String myOption,
    ) {
        ...
    }

It's counterintuitive that the longName is not needed if a shortName is specified, since the shortName should be an additional way on top of the longName.

This works in 4.0 (no need to specify longName because a shortName is specified):

    @Command(name = "test", description = "Test command.")
    public void build(
        @Option(description = "Some option.",  shortName = "o") String myOption,
    ) {
        ...
    }

I'm available to help with a potential PR.

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