decline-ts
Version:
Composable command-line parser for TypeScript - a (partial) porting of Scala decline using fp-ts
19 lines (18 loc) • 923 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Command = void 0;
const fp_ts_1 = require("fp-ts");
const function_1 = require("fp-ts/function");
const Help_1 = require("./Help");
const Opts_1 = require("./Opts");
const Parser_1 = require("./Parser");
function Command({ name, header }) {
return opts => ({ _tag: 'Command', name, header, opts });
}
exports.Command = Command;
(function (Command) {
Command.parseHelp = (args) => (cmd) => Parser_1.Parser(cmd)(args);
Command.parse = (args) => function_1.flow(Command.parseHelp(args), fp_ts_1.either.mapLeft(Help_1.Help.stringify));
Command.mapValidated = (f) => (cmd) => Command({ name: cmd.name, header: cmd.header })(function_1.pipe(cmd.opts, Opts_1.Opts.mapValidated(f)));
Command.map = (f) => Command.mapValidated(function_1.flow(f, fp_ts_1.either.right));
})(Command = exports.Command || (exports.Command = {}));