UNPKG

justo.plugin.cli

Version:

Justo plugin for running commands from the shell.

25 lines (23 loc) 1.71 kB
"use strict"; var _dogmalang = require("dogmalang"); function cli(params, ssh) { let res;_dogmalang.dogma.paramExpectedToHave("params", params, { cmd: { type: _dogmalang.text, mandatory: true }, detach: { type: _dogmalang.bool, mandatory: false }, wd: { type: _dogmalang.text, mandatory: false }, status: { type: [_dogmalang.list, _dogmalang.text, _dogmalang.num], mandatory: false }, env: { type: _dogmalang.map, mandatory: false } }, true);_dogmalang.dogma.paramExpectedToBe("ssh", ssh, _dogmalang.func);if (params.status != null) params.status = (0, _dogmalang.list)(params.status);{ if (ssh) { res = ssh(params.cmd); } else { _dogmalang.dogma.update(params, { name: "status", visib: ".", assign: "?=", value: [0] }, { name: "print", visib: ".", assign: "?=", value: _dogmalang.print }, { name: "printe", visib: ".", assign: "?=", value: console.error });if (params.detach) { res = (0, _dogmalang.exec)(params.cmd, { ["detach"]: true, ["workDir"]: params.wd || params.workDir, ["env"]: params.env }); } else { try { res = { ["status"]: 0, ["stdout"]: (0, _dogmalang.exec)(params.cmd, { ["workDir"]: params.wd || params.workDir, ["env"]: params.env }) };if (params.status != "any" && !_dogmalang.dogma.includes(params.status, 0)) { _dogmalang.dogma.raise("status expected to be %s; received: 0.", params.status); } } catch (e) { if (params.status != "any" && !_dogmalang.dogma.includes(params.status, e.status)) { _dogmalang.dogma.raise(e); }res = { ["status"]: e.status, ["stdout"]: e.stdout, ["stderr"]: e.stderr }; } } } }return res; }module.exports = exports = cli;