@attest-it/cli 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -94,10 +94,14 @@ All commands support these global options:
94
94
 
95
95
  ## Exit Codes
96
96
 
97
- | Code | Meaning |
98
- | ---- | ---------------------------- |
99
- | 0 | Success |
100
- | 1 | Verification failed or error |
97
+ | Code | Constant | Meaning |
98
+ | ---- | ------------ | ----------------------------------- |
99
+ | 0 | SUCCESS | Operation completed successfully |
100
+ | 1 | FAILURE | Tests failed or attestation invalid |
101
+ | 2 | NO_WORK | Nothing needed attestation |
102
+ | 3 | CONFIG_ERROR | Configuration or validation error |
103
+ | 4 | CANCELLED | User cancelled the operation |
104
+ | 5 | MISSING_KEY | Missing required key file |
101
105
 
102
106
  ## Programmatic Usage
103
107
 
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
3
  import * as fs from 'fs';
4
+ import { readFileSync } from 'fs';
4
5
  import * as path from 'path';
5
- import { join, dirname } from 'path';
6
+ import { dirname, join } from 'path';
6
7
  import { detectTheme } from 'chromaterm';
7
8
  import { confirm } from '@inquirer/prompts';
8
9
  import { loadConfig, readAttestations, computeFingerprint, findAttestation, createAttestation, upsertAttestation, getDefaultPrivateKeyPath, writeSignedAttestations, checkOpenSSL, getDefaultPublicKeyPath, generateKeyPair, setKeyPermissions, verifyAttestations, toAttestItConfig } from '@attest-it/core';
@@ -13,6 +14,7 @@ import * as React7 from 'react';
13
14
  import { render, useApp, Box, Text, useInput } from 'ink';
14
15
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
15
16
  import { readFile, unlink, mkdir, writeFile } from 'fs/promises';
17
+ import { fileURLToPath } from 'url';
16
18
 
17
19
  var globalOptions = {};
18
20
  var theme;
@@ -1604,10 +1606,39 @@ function hasWarnings(result, maxAgeDays) {
1604
1606
  (s) => s.status === "VALID" && (s.age ?? 0) > maxAgeDays - warningThreshold
1605
1607
  );
1606
1608
  }
1607
-
1608
- // src/index.ts
1609
+ function hasVersion(data) {
1610
+ return typeof data === "object" && data !== null && "version" in data && // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1611
+ typeof data.version === "string";
1612
+ }
1613
+ var cachedVersion;
1614
+ function getPackageVersion() {
1615
+ if (cachedVersion !== void 0) {
1616
+ return cachedVersion;
1617
+ }
1618
+ const __filename = fileURLToPath(import.meta.url);
1619
+ const __dirname = dirname(__filename);
1620
+ const possiblePaths = [join(__dirname, "../package.json"), join(__dirname, "../../package.json")];
1621
+ for (const packageJsonPath of possiblePaths) {
1622
+ try {
1623
+ const content = readFileSync(packageJsonPath, "utf-8");
1624
+ const packageJsonData = JSON.parse(content);
1625
+ if (!hasVersion(packageJsonData)) {
1626
+ throw new Error(`Invalid package.json at ${packageJsonPath}: missing version field`);
1627
+ }
1628
+ cachedVersion = packageJsonData.version;
1629
+ return cachedVersion;
1630
+ } catch (error2) {
1631
+ if (error2 instanceof Error && "code" in error2 && error2.code === "ENOENT") {
1632
+ continue;
1633
+ }
1634
+ throw error2;
1635
+ }
1636
+ }
1637
+ throw new Error("Could not find package.json");
1638
+ }
1609
1639
  var program = new Command();
1610
- program.name("attest-it").description("Human-gated test attestation system").version("0.0.1").option("-c, --config <path>", "Path to config file").option("-v, --verbose", "Verbose output").option("-q, --quiet", "Minimal output");
1640
+ program.name("attest-it").description("Human-gated test attestation system").option("-c, --config <path>", "Path to config file").option("-v, --verbose", "Verbose output").option("-q, --quiet", "Minimal output");
1641
+ program.option("-V, --version", "output the version number");
1611
1642
  program.addCommand(initCommand);
1612
1643
  program.addCommand(statusCommand);
1613
1644
  program.addCommand(runCommand);
@@ -1615,6 +1646,10 @@ program.addCommand(keygenCommand);
1615
1646
  program.addCommand(pruneCommand);
1616
1647
  program.addCommand(verifyCommand);
1617
1648
  async function run() {
1649
+ if (process.argv.includes("--version") || process.argv.includes("-V")) {
1650
+ console.log(getPackageVersion());
1651
+ process.exit(0);
1652
+ }
1618
1653
  await initTheme();
1619
1654
  program.parse();
1620
1655
  const options = program.opts();