UNPKG

diesel

Version:

Dumb Interpretively Executed String Expression Language

75 lines (74 loc) 2.99 kB
#!/usr/bin/env node "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_process_1 = __importDefault(require("node:process")); const node_util_1 = require("node:util"); const index_1 = require("./index"); const args = (0, node_util_1.parseArgs)({ allowPositionals: true, options: { help: { type: "boolean", short: "h", }, }, }); (function () { return __awaiter(this, void 0, void 0, function* () { if (node_process_1.default.stdin.isTTY) { if (args.positionals.length > 0) { try { const evaluated = yield (0, index_1.evaluate)(args.positionals[0]); console.log(evaluated); node_process_1.default.exit(0); } catch (err) { if (err instanceof index_1.DieselError) { console.error(err.message); } else { console.error(err); } node_process_1.default.exit(1); } } if (args.values.help || Object.keys(args.values).length === 0) { console.log([ "NAME", " diesel - Dumb Interpretively Executed String Expression Language", "", "SYNOPSIS", " diesel [EXPRESSION]", "", "DESCRIPTION", " diesel is the kernel of a macro language you can customise", " by adding C code and embedding it into your program.", "", "OPTIONS", " -h, --help", " Display the help message and exit.", "", "USAGE", " Evaluate an expression", "", " diesel '$(+,1,2,3,4,5)'", " output: 15", "", ].join("\n")); } } }); })();