Beispiel
args 2.7.0: Ensure option-like arguments and the double-dash separator after a positional argument are treated as literal positional arguments when allowTrailingOptions is disabled
Verifiziertes Beispiel für pub args 2.7.0: Ensure option-like arguments and the double-dash separator after a positional argument are treated as literal…
sha256:a8903858356386356972e088af4cc88ca064369aeb6c21d7e9db1fade9205dad
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 2
- Signaturschlüssel, die es gebaut haben
- 2
Deklarierte Umgebung
dart linux x64 dart dart pub
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| dart 3 · linux debian/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · pub@1 |
2026-08-16 |
| dart 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · pub@1 |
2026-08-18 |
Fall
HOW- Ziel
- Ensure option-like arguments and the double-dash separator after a positional argument are treated as literal positional arguments when allowTrailingOptions is disabled
- Pakete
- Symbole
-
- ArgParser
- ArgParser.allowTrailingOptions
- ArgResults.rest
- Umgebung
- dart
- Erstellt
- 2026-08-17T02:02:58Z
Contract
- Disabling allowTrailingOptions causes option-like arguments and the double-dash separator after a positional argument to be treated as literal positional arguments in results.rest rather than being parsed or consumed.
- assert parser with allowTrailingOptions: false treats --mode and --verbose after a positional argument as literal positional arguments in rest rather than parsing them
- assert parser with allowTrailingOptions: false preserves the double-dash separator in rest rather than consuming it
- assert default parser with allowTrailingOptions: true consumes the double-dash separator and parses options normally
Dateien
- NOTES.md
- csx.json
- pubspec.lock
- pubspec.yaml
- test/contract.dart
Quelltext
Known-solution search: Prior samples for package:args were found, including goals related to comma-delimited options ("Preserve comma-delimited option values as single arguments in package:args by disabling splitCommas") and mandatory option validation.
Fails silently with a green build: Assuming option-like arguments and the double-dash `--` separator are still validated or parsed normally after a positional argument when `allowTrailingOptions` is false leads to silent argument parsing errors and misplaced arguments in the rest list while the build passes.
{"case":{"believed":"When allowTrailingOptions is false, option-like arguments after the first positional argument still trigger validation, and the double-dash separator is consumed as a special token.","caseId":"case:sha256:f59cc9e955b51edde43c8eb0b8b80259e28d4b98a2fe5659f5b326ccef9435f2","contract":["Disabling allowTrailingOptions causes option-like arguments and the double-dash separator after a positional argument to be treated as literal positional arguments in results.rest rather than being parsed or consumed.","assert parser with allowTrailingOptions: false treats --mode and --verbose after a positional argument as literal positional arguments in rest rather than parsing them","assert parser with allowTrailingOptions: false preserves the double-dash separator in rest rather than consuming it","assert default parser with allowTrailingOptions: true consumes the double-dash separator and parses options normally"],"goal":"Ensure option-like arguments and the double-dash separator after a positional argument are treated as literal positional arguments when allowTrailingOptions is disabled","kind":"HOW","packages":["pkg:pub/args@2.7.0"],"schemaVersion":1,"symbols":["ArgParser","ArgParser.allowTrailingOptions","ArgResults.rest"]},"contractCommand":["dart","test/contract.dart"],"environment":{"arch":"x64","ecosystem":"pub","executionContext":"dart","language":"dart","os":"linux","packageManager":"pub","runtime":"dart","schemaVersion":1},"license":"MIT-0","packages":["pkg:pub/args@2.7.0"],"schemaVersion":1,"symbols":["ArgParser","ArgParser.allowTrailingOptions","ArgResults.rest"],"verifierAdapter":"pub@1"}
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
args:
dependency: "direct main"
description:
name: args
sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04
url: "https://pub.dev"
source: hosted
version: "2.7.0"
sdks:
dart: ">=3.5.0 <4.0.0"
name: pub_args_contract
publish_to: none
environment:
sdk: ">=3.5.0 <4.0.0"
dependencies:
args: 2.7.0
import 'package:args/args.dart';
void main() {
// Scenario 1: With allowTrailingOptions: false, option-like arguments and flags
// placed after a positional argument are NOT parsed or validated as options,
// but are treated as literal positional arguments and appended to results.rest.
{
final parser = ArgParser(allowTrailingOptions: false)
..addOption('mode', abbr: 'm')
..addFlag('verbose');
// Parse arguments where positional 'pos' comes before unrecognized '--unknown'
// and declared '--mode'/'--verbose'.
// If they were parsed/validated, '--unknown' would throw a FormatException,
// and '--mode'/'--verbose' would set option/flag values.
final results = parser.parse(['pos', '--mode', 'release', '--verbose', '--unknown']);
// Assert that the mode option is NOT set to 'release' (it is null)
if (results['mode'] != null) {
throw StateError(
'Expected results["mode"] to be null because option parsing stopped, but got ${results["mode"]}',
);
}
// Assert that the verbose flag is NOT set to true (it is false)
if (results['verbose'] != false) {
throw StateError(
'Expected results["verbose"] to be false, but got ${results["verbose"]}',
);
}
// Assert that all arguments after the positional 'pos' are collected as literal positional arguments in rest
final expectedRest = ['pos', '--mode', 'release', '--verbose', '--unknown'];
if (results.rest.length != expectedRest.length) {
throw StateError('Expected results.rest length to be ${expectedRest.length}, got ${results.rest.length}');
}
for (var i = 0; i < expectedRest.length; i++) {
if (results.rest[i] != expectedRest[i]) {
throw StateError('Expected results.rest[$i] to be "${expectedRest[i]}", got "${results.rest[i]}"');
}
}
}
// Scenario 2: Under allowTrailingOptions: false, the double-dash '--' separator
// itself is NOT consumed when it appears after a positional argument,
// and is instead treated as a literal positional argument "--".
{
final parser = ArgParser(allowTrailingOptions: false)
..addOption('mode', abbr: 'm')
..addFlag('verbose');
final results = parser.parse(['pos', '--', '--verbose']);
// Assert that '--' is preserved in rest
final expectedRest = ['pos', '--', '--verbose'];
if (results.rest.length != expectedRest.length) {
throw StateError('Expected results.rest length to be ${expectedRest.length}, got ${results.rest.length}');
}
for (var i = 0; i < expectedRest.length; i++) {
if (results.rest[i] != expectedRest[i]) {
throw StateError('Expected results.rest[$i] to be "${expectedRest[i]}", got "${results.rest[i]}"');
}
}
}
// Scenario 3: Under default allowTrailingOptions: true, the double-dash '--' separator
// IS consumed, stopping option parsing and treating subsequent args as positional,
// but "--" itself is not returned in results.rest.
{
final parser = ArgParser(allowTrailingOptions: true)
..addOption('mode', abbr: 'm')
..addFlag('verbose');
final results = parser.parse(['pos', '--', '--verbose']);
// Assert that '--' is consumed and NOT preserved in rest, but '--verbose' is treated as positional
final expectedRest = ['pos', '--verbose'];
if (results.rest.length != expectedRest.length) {
throw StateError('Expected results.rest length to be ${expectedRest.length}, got ${results.rest.length}');
}
for (var i = 0; i < expectedRest.length; i++) {
if (results.rest[i] != expectedRest[i]) {
throw StateError('Expected results.rest[$i] to be "${expectedRest[i]}", got "${results.rest[i]}"');
}
}
}
}