1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
6 | return function (d, b) {
|
7 | extendStatics(d, b);
|
8 | function __() { this.constructor = d; }
|
9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
10 | };
|
11 | })();
|
12 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
13 | return new (P || (P = Promise))(function (resolve, reject) {
|
14 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
15 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
16 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
17 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
18 | });
|
19 | };
|
20 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
21 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
22 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
23 | function verb(n) { return function (v) { return step([n, v]); }; }
|
24 | function step(op) {
|
25 | if (f) throw new TypeError("Generator is already executing.");
|
26 | while (_) try {
|
27 | if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
28 | if (y = 0, t) op = [0, t.value];
|
29 | switch (op[0]) {
|
30 | case 0: case 1: t = op; break;
|
31 | case 4: _.label++; return { value: op[1], done: false };
|
32 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
33 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
34 | default:
|
35 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
36 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
37 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
38 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
39 | if (t[2]) _.ops.pop();
|
40 | _.trys.pop(); continue;
|
41 | }
|
42 | op = body.call(thisArg, _);
|
43 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
44 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
45 | }
|
46 | };
|
47 | var _this = this;
|
48 | Object.defineProperty(exports, "__esModule", { value: true });
|
49 |
|
50 | require("source-map-support/register");
|
51 | var Command_1 = require("./Command");
|
52 | var Flags_1 = require("./Flags");
|
53 | var Config_1 = require("./Config");
|
54 | var Command = (function (_super) {
|
55 | __extends(Command, _super);
|
56 | function Command() {
|
57 | return _super !== null && _super.apply(this, arguments) || this;
|
58 | }
|
59 | Command.topic = 'foo';
|
60 | Command.command = 'bar';
|
61 | Command.flags = { myflag: Flags_1.flags.boolean() };
|
62 | Command.args = [{ name: 'myarg', required: false }];
|
63 | return Command;
|
64 | }(Command_1.Command));
|
65 | test('shows the ID', function () {
|
66 | expect(Command.id).toEqual('foo:bar');
|
67 | });
|
68 | test('runs the command', function () { return __awaiter(_this, void 0, void 0, function () {
|
69 | var cmd;
|
70 | return __generator(this, function (_a) {
|
71 | switch (_a.label) {
|
72 | case 0: return [4 , Command.mock()];
|
73 | case 1:
|
74 | cmd = _a.sent();
|
75 | expect(cmd.flags).toEqual({});
|
76 | expect(cmd.argv).toEqual([]);
|
77 | return [2 ];
|
78 | }
|
79 | });
|
80 | }); });
|
81 | test('has stdout', function () { return __awaiter(_this, void 0, void 0, function () {
|
82 | var Command, stdout;
|
83 | return __generator(this, function (_a) {
|
84 | switch (_a.label) {
|
85 | case 0:
|
86 | Command = (function (_super) {
|
87 | __extends(Command, _super);
|
88 | function Command() {
|
89 | return _super !== null && _super.apply(this, arguments) || this;
|
90 | }
|
91 | Command.prototype.run = function () {
|
92 | return __awaiter(this, void 0, void 0, function () {
|
93 | return __generator(this, function (_a) {
|
94 | this.out.stdout.log(this.flags.print);
|
95 | return [2 ];
|
96 | });
|
97 | });
|
98 | };
|
99 | Command.flags = {
|
100 | print: Flags_1.flags.string(),
|
101 | bool: Flags_1.flags.boolean()
|
102 | };
|
103 | return Command;
|
104 | }(Command_1.Command));
|
105 | return [4 , Command.mock('--print=foo')];
|
106 | case 1:
|
107 | stdout = (_a.sent()).stdout;
|
108 | expect(stdout).toEqual('foo\n');
|
109 | return [2 ];
|
110 | }
|
111 | });
|
112 | }); });
|
113 | test('has stderr', function () { return __awaiter(_this, void 0, void 0, function () {
|
114 | var Command, stderr;
|
115 | return __generator(this, function (_a) {
|
116 | switch (_a.label) {
|
117 | case 0:
|
118 | Command = (function (_super) {
|
119 | __extends(Command, _super);
|
120 | function Command() {
|
121 | return _super !== null && _super.apply(this, arguments) || this;
|
122 | }
|
123 | Command.prototype.run = function () {
|
124 | return __awaiter(this, void 0, void 0, function () {
|
125 | return __generator(this, function (_a) {
|
126 | this.out.stderr.log(this.flags.print);
|
127 | return [2 ];
|
128 | });
|
129 | });
|
130 | };
|
131 | Command.flags = { print: Flags_1.flags.string() };
|
132 | return Command;
|
133 | }(Command_1.Command));
|
134 | return [4 , Command.mock('--print=foo')];
|
135 | case 1:
|
136 | stderr = (_a.sent()).stderr;
|
137 | expect(stderr).toEqual('foo\n');
|
138 | return [2 ];
|
139 | }
|
140 | });
|
141 | }); });
|
142 | test('parses args', function () { return __awaiter(_this, void 0, void 0, function () {
|
143 | var cmd;
|
144 | return __generator(this, function (_a) {
|
145 | switch (_a.label) {
|
146 | case 0: return [4 , Command.mock('one')];
|
147 | case 1:
|
148 | cmd = _a.sent();
|
149 | expect(cmd.flags).toEqual({});
|
150 | expect(cmd.argv).toEqual(['one']);
|
151 | expect(cmd.args).toEqual({ myarg: 'one' });
|
152 | return [2 ];
|
153 | }
|
154 | });
|
155 | }); });
|
156 | test('has help', function () { return __awaiter(_this, void 0, void 0, function () {
|
157 | var Command, config;
|
158 | return __generator(this, function (_a) {
|
159 | Command = (function (_super) {
|
160 | __extends(Command, _super);
|
161 | function Command() {
|
162 | return _super !== null && _super.apply(this, arguments) || this;
|
163 | }
|
164 | Command.topic = 'config';
|
165 | Command.command = 'get';
|
166 | Command.help = "this is\n\nsome multiline help\n";
|
167 | return Command;
|
168 | }(Command_1.Command));
|
169 | config = new Config_1.Config({ mock: true });
|
170 | expect(Command.buildHelp(config)).toMatchSnapshot('buildHelp');
|
171 | expect(Command.buildHelpLine(config)).toMatchSnapshot('buildHelpLine');
|
172 | return [2 ];
|
173 | });
|
174 | }); });
|
175 |
|
\ | No newline at end of file |