CodeSampleX

サンプル

cac 6.7.14: cac

検証済みサンプル — npm cac 6.7.14: cac. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: cac initializes a CAC command-line application instance with an…

sha256:1de1e1c6f7e9997a9f2c1038eb45803f2d1e1736be1c871ba50c3f15c6412209

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
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-06

ケース

HOW
ゴール
verify cac.cac in pkg:npm/cac@6.7.14
パッケージ
シンボル
  • cac.cac
環境
node 22.23.2
作成日
2026-09-06T11:45:42Z

コントラクト

  1. cac initializes a CAC command-line application instance with an optional program name
  2. cac registers sub-commands and passes parsed arguments and command options to action callbacks
  3. cac registers global options with default values and parses user supplied option values
  4. cac parses negated boolean flags into false boolean option properties
  5. cac parses variadic arguments for sub-commands into an array of strings

ファイル

  • .npmrc
  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • test/contract.mjs

ソースアーティファクトをダウンロード (tar.gz)

ソース

.npmrc
audit=false
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 cac.cac in pkg:npm/cac@6.7.14
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/cac@6.7.14
Demonstrate these symbols/APIs:
  - cac.cac

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:5af70f52992c783249849e3a37cb6701e94f437081cf94809b32a9925f3f2e56","contract":["cac initializes a CAC command-line application instance with an optional program name","cac registers sub-commands and passes parsed arguments and command options to action callbacks","cac registers global options with default values and parses user supplied option values","cac parses negated boolean flags into false boolean option properties","cac parses variadic arguments for sub-commands into an array of strings"],"goal":"verify cac.cac in pkg:npm/cac@6.7.14","kind":"HOW","packages":["pkg:npm/cac@6.7.14"],"schemaVersion":1,"symbols":["cac.cac"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/cac@6.7.14"],"schemaVersion":1,"subject":"pkg:npm/cac@6.7.14","symbols":["cac.cac"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-cac",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-cac",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "cac": "6.7.14"
      }
    },
    "node_modules/cac": {
      "version": "6.7.14",
      "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz",
      "integrity": "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    }
  }
}
package.json
{
  "name": "sample-cac",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "description": "verify cac.cac in pkg:npm/cac@6.7.14",
  "main": "src/index.mjs",
  "license": "MIT-0",
  "dependencies": {
    "cac": "6.7.14"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify cac.cac in pkg:npm/cac@6.7.14",
  "kind": "HOW",
  "packages": [
    "pkg:npm/cac@6.7.14"
  ],
  "symbols": [
    "cac.cac"
  ]
}
src/index.mjs
import { cac, CAC, Command } from 'cac';

/**
 * Creates a CAC CLI application instance.
 *
 * @param {string} [name] - Optional program name
 * @returns {CAC} CAC application instance
 */
export function createCli(name) {
  return cac(name);
}

export { cac, CAC, Command };
export default cac;
test/contract.mjs
import assert from 'node:assert/strict';
import { cac, CAC, Command, createCli } from '../src/index.mjs';

// 1. cac initializes a CAC command-line application instance with an optional program name
{
  const namedCli = cac('sample-app');
  assert.equal(namedCli instanceof CAC, true);
  assert.equal(namedCli.name, 'sample-app');

  const defaultCli = cac();
  assert.equal(defaultCli instanceof CAC, true);
  assert.equal(defaultCli.name, '');

  const helperCli = createCli('helper-app');
  assert.equal(helperCli instanceof CAC, true);
  assert.equal(helperCli.name, 'helper-app');
}

// 2. cac registers sub-commands and passes parsed arguments and command options to action callbacks
{
  const cli = cac();
  let actionInvoked = false;
  let receivedTarget = null;
  let receivedOptions = null;

  const command = cli.command('build <target>', 'Build artifact')
    .option('--minify', 'Minify output bundle')
    .action((target, options) => {
      actionInvoked = true;
      receivedTarget = target;
      receivedOptions = options;
    });

  assert.equal(command instanceof Command, true);

  const parsed = cli.parse(['node', 'cli.js', 'build', 'bundle.js', '--minify']);
  assert.equal(actionInvoked, true);
  assert.equal(receivedTarget, 'bundle.js');
  assert.equal(receivedOptions.minify, true);
  assert.deepEqual(parsed.args, ['bundle.js']);
  assert.equal(parsed.options.minify, true);
}

// 3. cac registers global options with default values and parses user supplied option values
{
  const cli = cac();
  cli.option('--format <type>', 'Output format', { default: 'esm' });

  const parsedDefault = cli.parse(['node', 'cli.js']);
  assert.equal(parsedDefault.options.format, 'esm');

  const parsedCustom = cli.parse(['node', 'cli.js', '--format', 'cjs']);
  assert.equal(parsedCustom.options.format, 'cjs');
}

// 4. cac parses negated boolean flags into false boolean option properties
{
  const cli = cac();
  cli.option('--sourcemap', 'Emit source maps', { default: true });

  const parsed = cli.parse(['node', 'cli.js', '--no-sourcemap']);
  assert.equal(parsed.options.sourcemap, false);
}

// 5. cac parses variadic arguments for sub-commands into an array of strings
{
  const cli = cac();
  let capturedFiles = null;

  cli.command('lint [...files]', 'Lint specified files')
    .action((files) => {
      capturedFiles = files;
    });

  cli.parse(['node', 'cli.js', 'lint', 'file1.js', 'file2.js', 'file3.js']);
  assert.deepEqual(capturedFiles, ['file1.js', 'file2.js', 'file3.js']);
}

オリジンシーダー

匿名