Skip to content

Improve error reporting when non mandatory options are misconfigured or not incorrectly specified at runtime #1245

@czpilar

Description

@czpilar

This seems like regression from some of the latests commits.

Consider this configuration:

@SpringBootApplication
public class SpringShellApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringShellApplication.class, args);
    }

    @Command(name = "hello", completionProvider = "helloNameCompletionProvider")
    public void sayHello(@Option(longName = "name", shortName = 'n') String name) {
        System.out.println("Hello " + name + "!");
    }

    @Bean
    public CompletionProvider helloNameCompletionProvider() {
        return completionContext -> Stream.of("Peter", "Paul", "Mary").map(CompletionProposal::new).toList();
    }

}

There are some issues:

  1. If a command is invoked without any option, the warning is logged. Which is not consistent if command is invoked with and option without value (there is no warning message).

    shell:>hello
    11:32:19.249 [main] WARN  o.s.s.c.c.a.MethodInvokerCommandAdapter - No value provided for optional option '--name' and no default value specified.
    Hello !
    
    shell:>hello --name
    Hello !
    
    shell:>hello -n
    Hello !
    
  2. If option is specified with a short or long name with space before the value, it's not recognized.

    shell:>hello --name Paul
    Hello !
    
    shell:>hello -n Paul
    Hello !
    
  3. The value is recognized only if specified with equal sign.

    shell:>hello --name=Paul
    Hello Paul!
    
    shell:>hello -n=Paul
    Hello Paul!
    
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions