#!/usr/bin/env node /** * Command-line interface for proofery. */ import * as fs from 'fs'; import { parseFileSync } from './nodeParser.js'; import { verifyFile } from './verifier.js'; import { VerificationError, ParseError } from './errors.js'; function main(): void { const args = process.argv.slice(2); // Parse command line arguments let verbose = false; let filepath: string | null = null; for (let i = 0; i < args.length; i++) { const arg = args[i]; if (arg === '--verbose' || arg === '-v') { verbose = true; } else if (arg === '--help' || arg === '-h') { printHelp(); process.exit(0); } else if (!arg.startsWith('-')) { filepath = arg; } else { console.error(`Unknown option: ${arg}`); printHelp(); process.exit(1); } } if (!filepath) { console.error('Error: No file specified'); printHelp(); process.exit(1); } try { // Check if file exists if (!fs.existsSync(filepath)) { console.error(`Error: File '${filepath}' not found`); process.exit(1); } // Parse the file if (verbose) { console.log(`Parsing ${filepath}...`); } const blocks = parseFileSync(filepath); if (verbose) { console.log(`Parsed ${blocks.length} top-level blocks\n`); } // Verify the proofs verifyFile(blocks, verbose); if (verbose) { console.log('\n✓ All proofs verified successfully!'); } process.exit(0); } catch (error) { if (error instanceof VerificationError || error instanceof ParseError || error instanceof SyntaxError) { console.error(`Error: ${error.message}`); process.exit(1); } else if (error instanceof Error) { console.error(`Unexpected error: ${error.message}`); if (verbose && error.stack) { console.error(error.stack); } process.exit(1); } else { console.error(`Unexpected error: ${error}`); process.exit(1); } } } function printHelp(): void { console.log(` proofery - A mathematical proof verifier Usage: proofery [options] Arguments: Path to the .prf file to verify Options: -v, --verbose Enable verbose output -h, --help Show this help message Example: proofery --verbose example.prf `); } main();