Skip to content

ShellOption not registered without hyphens #575

Closed
@Nimelrian

Description

@Nimelrian

I have noticed that after upgrading from 2.0.0-M3 to 2.1.3, parsing of method options failed for options annotated with @ShellOption if its value does not start with a leading -.

✔️ Case 1: No ShellOption annotation

Code:

@ShellComponent
public class Commands {
    @ShellMethod(key = "echo")
    public String echo(String message) {
        return "Echoing: " + message;
    }
}

Shell input / output:

shell:> echo Hello
Echoing: Hello

✔️ Case 2: ShellOption annotation with leading --

Code:

@ShellComponent
public class Commands {
    @ShellMethod(key = "echo")
    public String echo(@ShellOption("--msg") String message) {
        return "Echoing: " + message;
    }
}

Shell input / output:

shell:>echo --msg Hello
Echoing: Hello
shell:>echo Hello
Echoing: Hello

✔️ Case 3: ShellOption annotation with leading - and single character name

Code:

@ShellComponent
public class Commands {
    @ShellMethod(key = "echo")
    public String echo(@ShellOption("-m") String message) {
        return "Echoing: " + message;
    }
}

Shell input / output:

shell:>echo -m Hello
Echoing: Hello
shell:>echo Hello
Echoing: Hello

❌ Case 4: ShellOption annotation without leading - / -- and long name

Code:

@ShellComponent
public class Commands {
    @ShellMethod(key = "echo")
    public String echo(@ShellOption("msg") String message) {
        return "Echoing: " + message;
    }
}

Shell input / output:

shell:>help echo
NAME
       echo - 

SYNOPSIS
       echo 

OPTIONS


shell:>echo Hello
Echoing: null
shell:>echo "Hello"
Echoing: null
shell:>echo msg="Hello"
Echoing: null
shell:>echo --msg "Hello"
Echoing: null

Application log, no warnings given:

2022-11-24 18:33:54.638  INFO 246172 --- [           main] c.e.s.ShelloptionReproApplication        : Starting ShelloptionReproApplication using Java 17.0.5 on ...
2022-11-24 18:33:54.641  INFO 246172 --- [           main] c.e.s.ShelloptionReproApplication        : No active profile set, falling back to 1 default profile: "default"
2022-11-24 18:33:55.014  WARN 246172 --- [           main] org.jline                                : Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
2022-11-24 18:33:55.079  WARN 246172 --- [           main] org.jline                                : The Parser of class org.springframework.shell.jline.ExtendedDefaultParser does not support the CompletingParsedLine interface. Completion with escaped or quoted words won't work correctly.
2022-11-24 18:33:55.113  INFO 246172 --- [           main] c.e.s.ShelloptionReproApplication        : Started ShelloptionReproApplication in 0.732 seconds (JVM running for 0.985)

This worked in 2.0.0-M3 and is still demonstrated in the docs as a way to define option names if one doesn't want to use the parameter name:

// tag::option-with-annotation[]
public String example(@ShellOption(value = { "argx" }) String arg1) {
return "Hello " + arg1;
}
// end::option-with-annotation[]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions