Beispiel
commander 9.5.0: Option
Verifiziertes Beispiel für npm commander 9.5.0: Option. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: Option instantiates…
sha256:1e9d96e7de648833237131def62f7c32415122506290864f170df1df590b0335
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
- 1
Deklarierte Umgebung
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-23 |
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-07 |
Fall
HOW- Ziel
- verify commander.Option in pkg:npm/commander@9.5.0
- Pakete
- Symbole
-
- commander.Option
- Umgebung
- node 22.23.2
- Erstellt
- 2026-08-23T07:02:18Z
Contract
- Option instantiates command-line option definitions with flags, description, and argument requirement flags
- Option.choices restricts allowed option values and throws commander.invalidArgument when an invalid choice is provided
- Option.default sets a fallback default value for options when omitted
- Option.argParser transforms option values and validates syntax with custom parser functions or InvalidArgumentError
- Option.env configures environment variable fallback when an option is not supplied on the command line
- Option.makeOptionMandatory enforces required presence of the option throwing commander.missingMandatoryOptionValue when omitted
- Option.conflicts defines mutually exclusive options throwing commander.conflictingOption when both are specified
- Option.implies automatically sets additional option values when the option is present
Dateien
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.js
Quelltext
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 commander.Option in pkg:npm/commander@9.5.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/commander@9.5.0
Demonstrate these symbols/APIs:
- commander.Option
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:146ced8f14a05ac4f3eee726efbec378042768a025be0943f24fcda9fc1ea32b","constraints":{"executionContext":"node"},"contract":["Option instantiates command-line option definitions with flags, description, and argument requirement flags","Option.choices restricts allowed option values and throws commander.invalidArgument when an invalid choice is provided","Option.default sets a fallback default value for options when omitted","Option.argParser transforms option values and validates syntax with custom parser functions or InvalidArgumentError","Option.env configures environment variable fallback when an option is not supplied on the command line","Option.makeOptionMandatory enforces required presence of the option throwing commander.missingMandatoryOptionValue when omitted","Option.conflicts defines mutually exclusive options throwing commander.conflictingOption when both are specified","Option.implies automatically sets additional option values when the option is present"],"goal":"verify commander.Option in pkg:npm/commander@9.5.0","kind":"HOW","packages":["pkg:npm/commander@9.5.0"],"schemaVersion":1,"symbols":["commander.Option"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/commander@9.5.0"],"schemaVersion":1,"subject":"pkg:npm/commander@9.5.0","symbols":["commander.Option"],"verifierAdapter":"node-typescript@1"}
'use strict';
const { Command, Option, InvalidArgumentError } = require('commander');
/**
* Creates an Option instance with flags and description.
* @param {string} flags
* @param {string} description
* @returns {Option}
*/
function createOption(flags, description) {
return new Option(flags, description);
}
/**
* Configures a command with a choice-restricted option and optional default.
* @param {string} flags
* @param {string} description
* @param {string[]} choices
* @param {*} [defaultValue]
* @returns {Command}
*/
function createChoiceCommand(flags, description, choices, defaultValue) {
const program = new Command().exitOverride();
const opt = new Option(flags, description).choices(choices);
if (defaultValue !== undefined) {
opt.default(defaultValue);
}
program.addOption(opt);
return program;
}
/**
* Configures a command with a custom parser option.
* @param {string} flags
* @param {string} description
* @param {Function} parserFn
* @param {*} [defaultValue]
* @returns {Command}
*/
function createParsedOptionCommand(flags, description, parserFn, defaultValue) {
const program = new Command().exitOverride();
const opt = new Option(flags, description).argParser(parserFn);
if (defaultValue !== undefined) {
opt.default(defaultValue);
}
program.addOption(opt);
return program;
}
/**
* Configures a command with an environment variable fallback option.
* @param {string} flags
* @param {string} description
* @param {string} envVar
* @returns {Command}
*/
function createEnvOptionCommand(flags, description, envVar) {
const program = new Command().exitOverride();
const opt = new Option(flags, description).env(envVar);
program.addOption(opt);
return program;
}
/**
* Configures a command with a mandatory option.
* @param {string} flags
* @param {string} description
* @returns {Command}
*/
function createMandatoryOptionCommand(flags, description) {
const program = new Command().exitOverride();
const opt = new Option(flags, description).makeOptionMandatory(true);
program.addOption(opt);
return program;
}
/**
* Configures a command with mutually exclusive (conflicting) options.
* @param {Option} opt1
* @param {Option} opt2
* @returns {Command}
*/
function createConflictingOptionsCommand(opt1, opt2) {
const program = new Command().exitOverride();
program.addOption(opt1).addOption(opt2);
return program;
}
/**
* Configures a command with an option that implies other option values.
* @param {string} flags
* @param {string} description
* @param {object} impliedValues
* @returns {Command}
*/
function createImpliedOptionCommand(flags, description, impliedValues) {
const program = new Command().exitOverride();
const opt = new Option(flags, description).implies(impliedValues);
program.addOption(opt);
return program;
}
module.exports = {
Command,
Option,
InvalidArgumentError,
createOption,
createChoiceCommand,
createParsedOptionCommand,
createEnvOptionCommand,
createMandatoryOptionCommand,
createConflictingOptionsCommand,
createImpliedOptionCommand
};
{
"name": "sample-commander-option",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-commander-option",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"commander": "9.5.0"
}
},
"node_modules/commander": {
"version": "9.5.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz",
"integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==",
"license": "MIT",
"engines": {
"node": "^12.20.0 || >=14"
}
}
}
}
{
"name": "sample-commander-option",
"version": "1.0.0",
"private": true,
"description": "verify commander.Option in pkg:npm/commander@9.5.0",
"main": "index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"commander": "9.5.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify commander.Option in pkg:npm/commander@9.5.0",
"kind": "HOW",
"packages": [
"pkg:npm/commander@9.5.0"
],
"symbols": [
"commander.Option"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const assert = require('assert');
const {
Command,
Option,
InvalidArgumentError,
createOption,
createChoiceCommand,
createParsedOptionCommand,
createEnvOptionCommand,
createMandatoryOptionCommand,
createConflictingOptionsCommand,
createImpliedOptionCommand
} = require('../index.js');
function testOptionInstantiation() {
const reqOpt = createOption('-f, --flavor <type>', 'flavor type');
assert.strictEqual(reqOpt.name(), 'flavor');
assert.strictEqual(reqOpt.attributeName(), 'flavor');
assert.strictEqual(reqOpt.flags, '-f, --flavor <type>');
assert.strictEqual(reqOpt.description, 'flavor type');
assert.strictEqual(reqOpt.required, true);
assert.strictEqual(reqOpt.optional, false);
assert.strictEqual(reqOpt.isBoolean(), false);
const optOpt = createOption('-s, --size [size]', 'optional size');
assert.strictEqual(optOpt.name(), 'size');
assert.strictEqual(optOpt.required, false);
assert.strictEqual(optOpt.optional, true);
assert.strictEqual(optOpt.isBoolean(), false);
const boolOpt = createOption('-v, --verbose', 'enable verbose logging');
assert.strictEqual(boolOpt.name(), 'verbose');
assert.strictEqual(boolOpt.required, false);
assert.strictEqual(boolOpt.optional, false);
assert.strictEqual(boolOpt.isBoolean(), true);
const hiddenOpt = createOption('--secret', 'hidden option').hideHelp(true);
assert.strictEqual(hiddenOpt.hidden, true);
}
function testOptionChoices() {
const choices = ['small', 'medium', 'large'];
const program = createChoiceCommand('-s, --size <size>', 'drink size', choices, 'medium');
program.parse(['node', 'app', '--size', 'large']);
assert.strictEqual(program.opts().size, 'large');
const invalidProgram = createChoiceCommand('-s, --size <size>', 'drink size', choices);
assert.throws(
() => {
invalidProgram.parse(['node', 'app', '--size', 'extra-large']);
},
(err) => {
assert.strictEqual(err.code, 'commander.invalidArgument');
assert.match(err.message, /Allowed choices are small, medium, large/);
return true;
}
);
}
function testOptionDefault() {
const program = createChoiceCommand('-s, --size <size>', 'drink size', ['small', 'medium', 'large'], 'medium');
program.parse(['node', 'app']);
assert.strictEqual(program.opts().size, 'medium');
}
function testOptionArgParser() {
const parsePort = (val) => {
const port = parseInt(val, 10);
if (isNaN(port) || port < 1 || port > 65535) {
throw new InvalidArgumentError('Port must be between 1 and 65535.');
}
return port;
};
const program = createParsedOptionCommand('-p, --port <number>', 'listening port', parsePort);
program.parse(['node', 'app', '-p', '3000']);
assert.strictEqual(program.opts().port, 3000);
const invalidProgram = createParsedOptionCommand('-p, --port <number>', 'listening port', parsePort);
assert.throws(
() => {
invalidProgram.parse(['node', 'app', '-p', 'invalid-port']);
},
(err) => {
assert.strictEqual(err.code, 'commander.invalidArgument');
assert.match(err.message, /Port must be between 1 and 65535/);
return true;
}
);
}
function testOptionEnv() {
const envKey = 'TEST_CSX_PORT';
process.env[envKey] = '8080';
const program = createEnvOptionCommand('-p, --port <number>', 'port number', envKey);
program.parse(['node', 'app']);
assert.strictEqual(program.opts().port, '8080');
delete process.env[envKey];
}
function testOptionMandatory() {
const program = createMandatoryOptionCommand('-k, --key <apiKey>', 'api key parameter');
assert.throws(
() => {
program.parse(['node', 'app']);
},
(err) => {
assert.strictEqual(err.code, 'commander.missingMandatoryOptionValue');
return true;
}
);
const validProgram = createMandatoryOptionCommand('-k, --key <apiKey>', 'api key parameter');
validProgram.parse(['node', 'app', '-k', 'secret123']);
assert.strictEqual(validProgram.opts().key, 'secret123');
}
function testOptionConflicts() {
const quietOpt = createOption('-q, --quiet', 'quiet mode').conflicts('verbose');
const verboseOpt = createOption('-v, --verbose', 'verbose mode');
const program = createConflictingOptionsCommand(quietOpt, verboseOpt);
assert.throws(
() => {
program.parse(['node', 'app', '-q', '-v']);
},
(err) => {
assert.strictEqual(err.code, 'commander.conflictingOption');
return true;
}
);
}
function testOptionImplies() {
const program = createImpliedOptionCommand('--enable-all', 'enable all features', { trace: true, debug: true });
program.option('--trace', 'trace mode').option('--debug', 'debug mode');
program.parse(['node', 'app', '--enable-all']);
assert.strictEqual(program.opts().enableAll, true);
assert.strictEqual(program.opts().trace, true);
assert.strictEqual(program.opts().debug, true);
}
function run() {
testOptionInstantiation();
testOptionChoices();
testOptionDefault();
testOptionArgParser();
testOptionEnv();
testOptionMandatory();
testOptionConflicts();
testOptionImplies();
console.log('Contract tests passed successfully.');
process.exit(0);
}
run();
Ursprungs-Seeder
anonym