サンプル
clap_builder 4.6.2: Arg
検証済みサンプル — cargo clap_builder 4.6.2: Arg. rust 1 · linux alpine/x64 · docker で contract を実行し、成功しました: Arg::new configures id, short, long, visible_alias, and…
sha256:7efa6750affc10818130636e01fcb2c054cca1e9794408fdd2fa9c125fb624dd
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
linux · alpine · musl x64 cargo
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b… |
2026-10-22 |
ケース
HOW- ゴール
- verify Arg in pkg:cargo/clap_builder@4.6.2
- パッケージ
- シンボル
-
- Arg
- 作成日
- 2026-10-22T12:31:31Z
コントラクト
- Arg::new configures id, short, long, visible_alias, and action accessible via getters
- Arg::default_value supplies fallback when optional argument is omitted
- Arg::default_missing_value with num_args(0..=1) and require_equals(true) distinguishes bare flag from explicit =value
- Arg::value_delimiter with ArgAction::Append splits comma-separated inputs across occurrences
- Arg::conflicts_with rejects mutually exclusive flags with ErrorKind::ArgumentConflict
- Arg::required(true) rejects missing positional argument with ErrorKind::MissingRequiredArgument
ファイル
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
ソース
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "anstream"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
[[package]]
name = "anstyle-parse"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys",
]
[[package]]
name = "clap_builder"
version = "4.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f09628afdcc538b57f3c6341e9c8e9970f18e4a481690a64974d7023bd33548b"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_lex"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486"
[[package]]
name = "colorchoice"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "sample-clap-builder-arg"
version = "0.1.0"
dependencies = [
"clap_builder",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[package]
name = "sample-clap-builder-arg"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
clap_builder = "=4.6.2"
[[bin]]
name = "contract"
path = "test/contract.rs"
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify Arg in pkg:cargo/clap_builder@4.6.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/clap_builder@4.6.2
Demonstrate these symbols/APIs:
- Arg
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:5c5359623294e58b1c8c6f7ade8ab00a6c729325f32b55c9f26af85177913830","contract":["Arg::new configures id, short, long, visible_alias, and action accessible via getters","Arg::default_value supplies fallback when optional argument is omitted","Arg::default_missing_value with num_args(0..=1) and require_equals(true) distinguishes bare flag from explicit =value","Arg::value_delimiter with ArgAction::Append splits comma-separated inputs across occurrences","Arg::conflicts_with rejects mutually exclusive flags with ErrorKind::ArgumentConflict","Arg::required(true) rejects missing positional argument with ErrorKind::MissingRequiredArgument"],"goal":"verify Arg in pkg:cargo/clap_builder@4.6.2","kind":"HOW","packages":["pkg:cargo/clap_builder@4.6.2"],"schemaVersion":1,"symbols":["Arg"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/clap_builder@4.6.2"],"schemaVersion":1,"subject":"pkg:cargo/clap_builder@4.6.2","symbols":["Arg"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify Arg in pkg:cargo/clap_builder@4.6.2",
"kind": "HOW",
"packages": [
"pkg:cargo/clap_builder@4.6.2"
],
"symbols": [
"Arg"
]
}
use clap_builder::{Arg, ArgAction, Command};
pub fn build_arg_command() -> Command {
Command::new("arg-demo")
.arg(
Arg::new("output")
.short('o')
.long("output")
.visible_alias("out")
.action(ArgAction::Set)
.default_value("stdout")
.default_missing_value("default.log")
.num_args(0..=1)
.require_equals(true),
)
.arg(
Arg::new("tag")
.short('t')
.long("tag")
.action(ArgAction::Append)
.value_delimiter(','),
)
.arg(
Arg::new("quiet")
.short('q')
.long("quiet")
.action(ArgAction::SetTrue)
.conflicts_with("verbose"),
)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.action(ArgAction::Count),
)
.arg(
Arg::new("target")
.action(ArgAction::Set)
.required(true),
)
}
use clap_builder::error::ErrorKind;
use clap_builder::{Arg, ArgAction};
use sample_clap_builder_arg::build_arg_command;
fn main() {
// 1. Arg builder getters reflect configured id, short, long, aliases, and action
let inspected = Arg::new("format")
.short('f')
.long("format")
.visible_alias("fmt")
.action(ArgAction::Set)
.required(false);
assert_eq!(inspected.get_id().as_str(), "format");
assert_eq!(inspected.get_short(), Some('f'));
assert_eq!(inspected.get_long(), Some("format"));
assert_eq!(inspected.get_visible_aliases(), Some(vec!["fmt"]));
assert!(!inspected.is_required_set());
let cmd = build_arg_command();
// 2. Arg default_value applies when optional argument is omitted, and required positional is parsed
let m1 = cmd
.clone()
.try_get_matches_from(["arg-demo", "build-target"])
.expect("default and positional should parse");
assert_eq!(
m1.get_one::<String>("output").map(String::as_str),
Some("stdout")
);
assert_eq!(
m1.get_one::<String>("target").map(String::as_str),
Some("build-target")
);
// 3. Arg default_missing_value with num_args(0..=1) and require_equals(true) handles bare flag vs explicit value
let m2 = cmd
.clone()
.try_get_matches_from(["arg-demo", "--output", "build-target"])
.expect("bare --output should use default_missing_value");
assert_eq!(
m2.get_one::<String>("output").map(String::as_str),
Some("default.log")
);
let m3 = cmd
.clone()
.try_get_matches_from(["arg-demo", "--out=custom.log", "build-target"])
.expect("visible_alias with =value should parse");
assert_eq!(
m3.get_one::<String>("output").map(String::as_str),
Some("custom.log")
);
// 4. Arg value_delimiter(',') with ArgAction::Append splits delimited values across occurrences
let m4 = cmd
.clone()
.try_get_matches_from(["arg-demo", "-t", "alpha,beta", "--tag", "gamma", "build-target"])
.expect("delimited and appended tags should parse");
let tags: Vec<&str> = m4
.get_many::<String>("tag")
.expect("tags present")
.map(String::as_str)
.collect();
assert_eq!(tags, vec!["alpha", "beta", "gamma"]);
// 5. Arg conflicts_with rejects mutually exclusive arguments with ArgumentConflict
let conflict_err = cmd
.clone()
.try_get_matches_from(["arg-demo", "--quiet", "-v", "build-target"])
.expect_err("quiet and verbose should conflict");
assert_eq!(conflict_err.kind(), ErrorKind::ArgumentConflict);
// 6. Arg required(true) rejects missing required argument with MissingRequiredArgument
let missing_err = cmd
.try_get_matches_from(["arg-demo", "-v"])
.expect_err("missing target should fail");
assert_eq!(missing_err.kind(), ErrorKind::MissingRequiredArgument);
}
オリジンシーダー
匿名