Skip to content

Incorrect handling of implicit --help option for sub-commands #1368

Closed

Description

@tschoellhorn

I am using Spring-Shell 4.0.3.

When defining a command via annotations the (implicit) -help-Option does not include a default-value:

@CommandGroup(name = "samples", prefix = "samples")
@Component
public class SampleCommand {

	@Command(
		name = "foo", 
		description = "Description of 'foo'", 
		help = "Help of 'foo'")
	public void foo(
		@Argument(index = 0, description = "The desc of value") int value, 
		@Option String name) {
		System.out.println("do it : " + name);
		System.out.println("value: " + value);
	}
	
	@Command(
		name = "bar", 
		description = "Description of 'bar'", 
		help = "Help of 'bar'")
	public void bar(
		@Arguments List<Integer> values, 
		@Option String name) {
		System.out.println("do it : " + name);
		System.out.println("values: " + values);
	}
}

When running samples bar --help I get an error message:

wdc:>samples bar --help
Error while parsing command: Option '--help' requires a value

When running samples bar --help true the help will be displayed.

Activity

  1. czpilar commented on Aug 22, 2026

    @czpilar
    Contributor

    Not related to CompletionProvider - the trigger is the @CommandGroup prefix.

    --help is implicit and never present in a command's getOptions(), so isBooleanOption() in DefaultCommandParser returns false for it and parsing throws. It only appears to work because of the special case near the top of parse(), which handles exactly the two-word input mycmd --help. With prefix = "samples" the full command name is samples bar, so the input is three words, the shortcut is skipped, and it fails. Same for samples foo - the parameter types are irrelevant.

    The same gap also mis-parses mycommand --help arg1, where --help silently swallows arg1 as its value.

    Fix: have isBooleanOption() treat --help/-h as a boolean flag when no declared option matches that name (the guard keeps commands that use -h for something else working). I have a patch with tests if it's useful.

  2. czpilar commented on Aug 22, 2026

    @czpilar
    Contributor

    Fixed in PR #1369

  3. tschoellhorn commented on Aug 23, 2026

    @tschoellhorn
    Author

    This is great. Thank you for looking into it!

  4. changed the title [-]--help not working when using a CompletionProvider[/-] [+]Incorrect handling of implicit --help option for sub-commands[/+] on Sep 21, 2026
  5. added this to the 4.0.4 milestone on Sep 21, 2026
  6. fmbenhassine commented on Sep 21, 2026

    @fmbenhassine
    Contributor

    This is a valid issue, thank you for reporting it. Planned it for next release.

    @czpilar Thank you for the follow up on this and for contributing a fix!

  7. added and removed
    status/need-triageTeam needs to triage and take a first look
    on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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