サンプル
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
検証済みサンプル — pub args 2.7.0: Ensure option-like arguments and the double-dash separator after a positional argument are treated as literal positional arguments…
sha256:a8903858356386356972e088af4cc88ca064369aeb6c21d7e9db1fade9205dad
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 2
- ビルドした署名鍵
- 2
宣言された環境
dart linux x64 dart dart pub
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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 |
ケース
HOW- ゴール
- Ensure option-like arguments and the double-dash separator after a positional argument are treated as literal positional arguments when allowTrailingOptions is disabled
- パッケージ
- シンボル
-
- ArgParser
- ArgParser.allowTrailingOptions
- ArgResults.rest
- 環境
- dart
- 作成日
- 2026-08-17T02:02:58Z
コントラクト
- 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
ファイル
- NOTES.md
- csx.json
- pubspec.lock
- pubspec.yaml
- test/contract.dart
ソース
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]}"');
}
}
}
}