required Boolean with non-default value
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the annotated command examples using Boolean and boolean, then inspect how @Option required, defaultValue, and help-menu optionality are processed. Compare omitted options with explicit true and false values; done means a required Boolean option has no implicit choice and the help output and command validation consistently reflect that.
Written by the indexing model from the issue text.
Description
spring shell version: 3.1.6
In one of my commands, I want to make sure that the end-user specifically indicates whether they either want A or B by using a Boolean. I don't want to make the choice for the end user.
When I add the following @Option on my command:
@Option(required = true, description = "Description", longNames = "Some long name") Boolean booleanOption
Spring Shell, automatically transforms the booleanOption to defaultValue false. The help menu of the command indicates that the booleanOption is optional.
When transforming into
@Option(required = true, description = "Description", longNames = "Some long name") boolean booleanOption
Still, the help menu indicates the booleanOption as optional. I assume for 2 reasons that this should not be the case: (1) it is a boolean and not Boolean. (2) required is explicitly set to true. The defaultValue is again false.
Setting the defaultValue to 'true' explicitly seems to be working.
@Option(required = true, description = "Description", longNames = "Some long name", defaultValue = "true")boolean booleanOption
It will show that the boolean is optional, but the default value will be true.
But again, I didn't want to choose for the user. I want the end user to articulate their choice when doing a command specifically.
If I write:
@Option(required = true, description = "Description", longNames = "Some long name", defaultValue = "")Boolean booleanOption
Or
@Option(required = true, description = "Description", longNames = "Some long name", defaultValue = "null")Boolean booleanOption
The defaultValue still translates to false (while as a Boolean I would expect it to be able to be null).
Is this the intended behavior?
- Dominant language
- Java
- Stars
- 826
- Forks
- 405
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from spring-projects/spring-shell
-
type/enhancement
Difficulty 3/5 1-2 days Newbie friendliness 68/100
spring-projects/spring-shell#1383 · 6 comments ·
-
area/dependencies type/enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
spring-projects/spring-shell#1213 · 1 reaction ·
-
area/dependencies type/enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
spring-projects/spring-shell#1205 · 1 comment ·
-
Spring CLI AI AgentOpenstatus/need-triage
Difficulty 5/5 Over a week Newbie friendliness 20/100
spring-projects/spring-shell#1198 · 2 comments ·
-
Add native buildOpenarea/build type/task
Difficulty 2/5 1-3 hours Newbie friendliness 42/100
spring-projects/spring-shell#1182 ·
All issues in spring-projects/spring-shell
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
apache/rocketmq-dashboard#5358 ·
Maintainers usually reply within 3 days
-
area:cpan-port area:database bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
fglock/PerlOnJava#1605 ·
Maintainers usually reply within 1 day
-
1.0.0-rc2
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wso2/dpdp-accelerator#377 ·
Maintainers usually reply within 1 day
-
area/dependencies backport/26.4 kind/cve severity/high source/scan-dependencies status/triage
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day