Skip to content

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

@mamachanko

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).

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