Repository navigation
Javadoc: Test how '!' marks a required option in PatternOptionBuilder - #449
Conversation
The Javadoc says '!' goes in front of a mandatory option, and its own example, "vp:!f/", is meant to make -f required. The flag was only applied once the next option character was read, so it ended up on the option before the '!': the example made -p required and left -f optional. It only worked when '!' was the first character of the pattern, which is the one case the tests covered. Now '!' applies to the option that follows it. A '!' with no option after it, as in "a:b!", used to land on the previous option; it now throws IllegalArgumentException, so a pattern written against the old behavior fails right away instead of quietly losing its required option. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@oscerd |
|
Hello @oscerd As you note this is a behavior breaking change. I want to confirm with you that this is really the intent. As always when the docs and code don't match we have to ask "What's the intent and ground truth for this feature?" and also how much does compatibility matter. What's confusing is that the PR doesn't update the documentation. The class still says Please review that code and docs match after changing code! ;) The code now explicitly throws Setting to draft. |
The earlier commit on this branch made '!' mark the option after it, following the 2008 Javadoc sentence "The exclamation mark precede a mandatory option". CLI-55 has the intent the other way round: "hc!<" makes -c mandatory, so '!' marks the option before it, which is what the code has always done and what the Javadoc now says. Back out that change so existing patterns keep working, and add tests for the current behavior instead: the Javadoc example, the CLI-55 example, a trailing '!' and several '!' in one pattern. Also say that a '!' at the start of the pattern marks the first option. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
|
Sorry Gary, I had it backwards. I went back to the history: in CLI-55 the example is Compatibility matters more here, so I've backed out the behavior change. Nothing changes for existing patterns and there's no new exception anymore. The PR now only adds tests for the current behavior (the Javadoc example, the CLI-55 example, a trailing P.S. 7dfda5b turned the |
|
Thank you @oscerd , merged 🚀 |
PatternOptionBuilderuses!to mark an option as required, and it has always applied it to the option before the!:parsePattern("vp:!f/")makes-pmandatory, and the CLI-55 example"hc!<"makes-cmandatory. A!at the start of the pattern marks the first option, which is the casetestRequiredOptioncovers. The class Javadoc now says "The exclamation mark makes the preceding option mandatory", but apart from that one test nothing pinned the behavior down.This adds tests for the Javadoc example, the CLI-55 example, a trailing
!and several!in one pattern, plus a sentence in the class Javadoc about a!at the start of the pattern. There's no behavior change.An earlier version of this PR changed
!to mark the following option instead. That was dropped to keep existing patterns working, see the discussion below.mvn; that'smvnon the command line by itself.🤖 Generated with Claude Code