CodeSampleX

Beispiel

clap 4.6.4: clap::Arg

Verifiziertes Beispiel für cargo clap 4.6.4: clap::Arg. Der Vertrag lief auf rust 1 · linux alpine/x64 · docker und bestand: clap::Arg::new configures id…

sha256:85db269ce87cbb36e043331f76866ed99fec26bed63cd1b5fee7dfc7bb483d73

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
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux x64 cargo

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify clap::Arg in pkg:cargo/clap@4.6.4
Pakete
Symbole
  • clap::Arg
Erstellt
2026-10-22T11:23:33Z

Contract

  1. clap::Arg::new configures id, short flag, long flag, value_name, required state, default_value, and ArgAction
  2. clap::Command with configured clap::Arg definitions parses matching CLI tokens and enforces required arguments

Dateien

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/main.rs
  • test/contract.rs

Quellartefakt herunterladen (tar.gz)

Quelltext

Cargo.lock
# 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"
version = "4.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d91e0c145792ef73a6ad36d27c75ac09f1832222a3c209689d90f534685ee5b7"
dependencies = [
 "clap_builder",
]

[[package]]
name = "clap-arg-sample"
version = "0.1.0"
dependencies = [
 "clap",
]

[[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 = "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",
]
Cargo.toml
[package]
name = "clap-arg-sample"
version = "0.1.0"
edition = "2021"

[[test]]
name = "contract"
path = "test/contract.rs"

[dependencies]
clap = "=4.6.4"
PROMPT.md
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 clap::Arg in pkg:cargo/clap@4.6.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/clap@4.6.4
Demonstrate these symbols/APIs:
  - clap::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.
csx.json
{"case":{"caseId":"case:sha256:00542abf0f4672bf94711c85f68d26a860a63ffaa6fb13876b3be3201778343a","contract":["clap::Arg::new configures id, short flag, long flag, value_name, required state, default_value, and ArgAction","clap::Command with configured clap::Arg definitions parses matching CLI tokens and enforces required arguments"],"goal":"verify clap::Arg in pkg:cargo/clap@4.6.4","kind":"HOW","packages":["pkg:cargo/clap@4.6.4"],"schemaVersion":1,"symbols":["clap::Arg"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/clap@4.6.4"],"schemaVersion":1,"subject":"pkg:cargo/clap@4.6.4","symbols":["clap::Arg"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify clap::Arg in pkg:cargo/clap@4.6.4",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/clap@4.6.4"
  ],
  "symbols": [
    "clap::Arg"
  ]
}
src/main.rs
use clap::{Arg, ArgAction, Command};

fn verify_clap_arg() {
    let input_arg = Arg::new("input")
        .short('i')
        .long("input")
        .value_name("FILE")
        .required(true)
        .action(ArgAction::Set);

    assert_eq!(input_arg.get_id().as_str(), "input");
    assert_eq!(input_arg.get_short(), Some('i'));
    assert_eq!(input_arg.get_long(), Some("input"));
    assert!(input_arg.is_required_set());

    let verbose_arg = Arg::new("verbose")
        .short('v')
        .long("verbose")
        .action(ArgAction::Count);

    let mode_arg = Arg::new("mode")
        .long("mode")
        .default_value("fast")
        .action(ArgAction::Set);

    let cmd = Command::new("demo")
        .arg(input_arg)
        .arg(verbose_arg)
        .arg(mode_arg);

    let matches = cmd
        .clone()
        .try_get_matches_from(["demo", "-i", "data.bin", "-vv"])
        .expect("valid arguments should parse");

    assert_eq!(
        matches.get_one::<String>("input").map(String::as_str),
        Some("data.bin")
    );
    assert_eq!(matches.get_count("verbose"), 2);
    assert_eq!(
        matches.get_one::<String>("mode").map(String::as_str),
        Some("fast")
    );

    let missing_required = cmd.try_get_matches_from(["demo"]);
    assert!(missing_required.is_err());
}

fn main() {
    verify_clap_arg();
}
test/contract.rs
use clap::{Arg, ArgAction, Command};

#[test]
fn contract_clap_arg() {
    let input_arg = Arg::new("input")
        .short('i')
        .long("input")
        .value_name("FILE")
        .required(true)
        .action(ArgAction::Set);

    assert_eq!(input_arg.get_id().as_str(), "input");
    assert_eq!(input_arg.get_short(), Some('i'));
    assert_eq!(input_arg.get_long(), Some("input"));
    assert!(input_arg.is_required_set());

    let verbose_arg = Arg::new("verbose")
        .short('v')
        .long("verbose")
        .action(ArgAction::Count);

    let mode_arg = Arg::new("mode")
        .long("mode")
        .default_value("fast")
        .action(ArgAction::Set);

    let cmd = Command::new("demo")
        .arg(input_arg)
        .arg(verbose_arg)
        .arg(mode_arg);

    let matches = cmd
        .clone()
        .try_get_matches_from(["demo", "-i", "data.bin", "-vv"])
        .expect("valid arguments should parse");

    assert_eq!(
        matches.get_one::<String>("input").map(String::as_str),
        Some("data.bin")
    );
    assert_eq!(matches.get_count("verbose"), 2);
    assert_eq!(
        matches.get_one::<String>("mode").map(String::as_str),
        Some("fast")
    );

    let missing_required = cmd.try_get_matches_from(["demo"]);
    assert!(missing_required.is_err());
}

Ursprungs-Seeder

anonym