Conversation
Counts the occurrences of a flag, and makes it accessible in the `ArgResult`. Only changes parser and result class, the `Option` class still treats flags as `bool` options, with a value that is `true` only when the count is greater than zero. Fixes #937.
PR HealthLicense Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
This check can be disabled by tagging the PR with API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
This check can be disabled by tagging the PR with Breaking changes ✔️
This check can be disabled by tagging the PR with Unused Dependencies ✔️
For details on how to fix these, see dependency_validator. This check can be disabled by tagging the PR with
Coverage
|
| File | Coverage |
|---|---|
| pkgs/args/lib/src/arg_results.dart | 💔 81 % ⬇️ 7 % |
| pkgs/args/lib/src/parser.dart | 💚 99 % ⬆️ 0 % |
This check for test coverage is informational (issues shown here will not fail the PR).
This check can be disabled by tagging the PR with skip-coverage-check.
Changelog Entry ✔️
| Package | Changed Files |
|---|
Changes to files need to be accounted for in their respective changelogs.
This check can be disabled by tagging the PR with skip-changelog-check.
| /// If a flag occurred more than once in the arguments, | ||
| /// this is the total number of counts. |
There was a problem hiding this comment.
[nit]
| /// If a flag occurred more than once in the arguments, | |
| /// this is the total number of counts. | |
| /// If a flag occurred more than once in the arguments, | |
| /// this is the total number of occurrences. |
| /// If the default is to be enabled, the default count is `1` if there were | ||
| /// no occurrences of the flag. |
There was a problem hiding this comment.
Is it worth describing specifically the behavior of passing the flag once when it is also the default?
There was a problem hiding this comment.
Probably best to do so. Just to be safe.
| throwsIllegalArg(() => results.multiOption('a')); | ||
| }); | ||
|
|
||
| test('flagCount', () { |
There was a problem hiding this comment.
[nit] I think it would be better to test these different flag behaviors in different test cases.
| parser.addFlag('negatable-flag', abbr: 'n', defaultsTo: false); | ||
|
|
||
| // Flags not occurring for testing default value. | ||
| parser.addFlag('default-true', abbr: 'd', defaultsTo: true); |
There was a problem hiding this comment.
[nit] Can you add a test case with a flag that defaults to true and is also passed? Also one that defaults to true and is negated with a --no flag.
|
Thanks, I was just looking for this when writing a CLI tool |
Counts the occurrences of a flag, and makes it accessible in the
ArgResult.Only changes parser and result class, the
Optionclass still treats flags asbooloptions, with a value that istrueonly when the count is greater than zero.Fixes #937.
(The
-vvis something I often use in my own scripts, and one reason for never using theargspackage.)