/ concept-collection / proofery
Sign in
concept-collection / proofery
proofery / src / cli.ts
101 lines · 2.5 KBBlameHistoryRaw
1#!/usr/bin/env node
2/**
3 * Command-line interface for proofery.
4 */
6import * as fs from 'fs';
7import { parseFileSync } from './nodeParser.js';
8import { verifyFile } from './verifier.js';
9import { VerificationError, ParseError } from './errors.js';
11function main(): void {
12 const args = process.argv.slice(2);
14 // Parse command line arguments
15 let verbose = false;
16 let filepath: string | null = null;
18 for (let i = 0; i < args.length; i++) {
19 const arg = args[i];
20 if (arg === '--verbose' || arg === '-v') {
21 verbose = true;
22 } else if (arg === '--help' || arg === '-h') {
23 printHelp();
24 process.exit(0);
25 } else if (!arg.startsWith('-')) {
26 filepath = arg;
27 } else {
28 console.error(`Unknown option: ${arg}`);
29 printHelp();
30 process.exit(1);
31 }
32 }
34 if (!filepath) {
35 console.error('Error: No file specified');
36 printHelp();
37 process.exit(1);
38 }
40 try {
41 // Check if file exists
42 if (!fs.existsSync(filepath)) {
43 console.error(`Error: File '${filepath}' not found`);
44 process.exit(1);
45 }
47 // Parse the file
48 if (verbose) {
49 console.log(`Parsing ${filepath}...`);
50 }
52 const blocks = parseFileSync(filepath);
54 if (verbose) {
55 console.log(`Parsed ${blocks.length} top-level blocks\n`);
56 }
58 // Verify the proofs
59 verifyFile(blocks, verbose);
61 if (verbose) {
62 console.log('\n✓ All proofs verified successfully!');
63 }
65 process.exit(0);
66 } catch (error) {
67 if (error instanceof VerificationError || error instanceof ParseError || error instanceof SyntaxError) {
68 console.error(`Error: ${error.message}`);
69 process.exit(1);
70 } else if (error instanceof Error) {
71 console.error(`Unexpected error: ${error.message}`);
72 if (verbose && error.stack) {
73 console.error(error.stack);
74 }
75 process.exit(1);
76 } else {
77 console.error(`Unexpected error: ${error}`);
78 process.exit(1);
79 }
80 }
83function printHelp(): void {
84 console.log(`
85proofery - A mathematical proof verifier
87Usage: proofery [options] <file>
89Arguments:
90 <file> Path to the .prf file to verify
92Options:
93 -v, --verbose Enable verbose output
94 -h, --help Show this help message
96Example:
97 proofery --verbose example.prf
98`);
101main();
moveopenescclose