Skip to content

Boolean flags not working without value in sub-commandsΒ #1331

Closed

Description

@mamachanko

This is a follow-up to #1309 but it's specific to sub-commands.

Steps taken

Consider the following application which with a command test with a sub-command sub-test which has an optional flag, i.e. a boolean argument, of name --force:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.shell.core.command.annotation.Command;
import org.springframework.shell.core.command.annotation.Option;

@SpringBootApplication
public class DemoApplication {

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

	@Command(name = "test sub-test")
	public void test(@Option() boolean force) {
		System.out.println("force = " + force);
	}

}

Expected behaviour

❯ ./mvnw -q spring-boot:run
...
$>test sub-test
force = false
$>test sub-test --force true
force = true
$>test sub-test --force
force = true

Actual behaviour

⚑ Error while parsing command: Option '--force' requires a value

❯ ./mvnw -q spring-boot:run
...
$>test sub-test
force = false
$>test sub-test --force true
force = true
$>test sub-test --force
Error while parsing command: Option '--force' requires a value

edit: I was able to confirm this on 4.0.1 and 4.0.2-SNAPSHOT (9dbdd71).

Activity

  1. czpilar commented on Apr 2, 2026

    @czpilar
    Contributor

    Fixed in PR #1333

  2. added and removed
    status/need-triageTeam needs to triage and take a first look
    on Apr 3, 2026
  3. added this to the 4.0.2 milestone on Apr 3, 2026
  4. added a commit that references this issue on Apr 3, 2026
    4f8bd1e
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