An experimental TypeSpec syntax for Lexicon

nicer error

+21 -4
-1
packages/cli/package.json
··· 1 { 2 "name": "@typelex/cli", 3 "version": "0.2.0", 4 - "description": "CLI for typelex - TypeSpec-based IDL for ATProto Lexicons", 5 "main": "dist/index.js", 6 "type": "module", 7 "bin": {
··· 1 { 2 "name": "@typelex/cli", 3 "version": "0.2.0", 4 "main": "dist/index.js", 5 "type": "module", 6 "bin": {
+21 -3
packages/cli/src/cli.ts
··· 13 (yargs) => { 14 return yargs 15 .positional("namespace", { 16 - describe: "Primary namespace pattern (e.g., app.bsky.*)", 17 type: "string", 18 demandOption: true, 19 }) 20 .option("out", { 21 - describe: "Output directory for generated Lexicon files (relative to cwd)", 22 type: "string", 23 default: "./lexicons", 24 }); 25 }, 26 async (argv) => { 27 const options: Record<string, unknown> = {}; 28 if (argv.watch) { 29 options.watch = true; ··· 39 type: "boolean", 40 default: false, 41 }) 42 - .demandCommand(1, "You must specify a command") 43 .help() 44 .version() 45 .fail((msg, err) => { 46 if (err) { 47 console.error(err); 48 } else { 49 console.error(msg); 50 }
··· 13 (yargs) => { 14 return yargs 15 .positional("namespace", { 16 + describe: "Primary namespace pattern (e.g., com.example.*)", 17 type: "string", 18 demandOption: true, 19 }) 20 .option("out", { 21 + describe: "Output directory for generated Lexicon files (must end with 'lexicons')", 22 type: "string", 23 default: "./lexicons", 24 }); 25 }, 26 async (argv) => { 27 + if (!argv.namespace) { 28 + console.error("Error: namespace is required"); 29 + console.error("Usage: typelex compile <namespace>"); 30 + console.error("Example: typelex compile com.example.*"); 31 + process.exit(1); 32 + } 33 + 34 + if (!argv.namespace.endsWith(".*")) { 35 + console.error("Error: namespace must end with .*"); 36 + console.error(`Got: ${argv.namespace}`); 37 + console.error("Example: typelex compile com.example.*"); 38 + process.exit(1); 39 + } 40 + 41 const options: Record<string, unknown> = {}; 42 if (argv.watch) { 43 options.watch = true; ··· 53 type: "boolean", 54 default: false, 55 }) 56 + .demandCommand(1) 57 .help() 58 .version() 59 .fail((msg, err) => { 60 if (err) { 61 console.error(err); 62 + } else if (msg.includes("Not enough non-option arguments")) { 63 + console.error("Error: namespace is required"); 64 + console.error("Usage: typelex compile <namespace>"); 65 + console.error("Example: typelex compile com.example.*"); 66 } else { 67 console.error(msg); 68 }