1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8 | });
|
9 | };
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | const command_1 = require("../models/command");
|
12 | const opn = require('opn');
|
13 | class DocCommand extends command_1.Command {
|
14 | constructor() {
|
15 | super(...arguments);
|
16 | this.name = 'doc';
|
17 | this.description = 'Opens the official Angular API documentation for a given keyword.';
|
18 | this.arguments = ['keyword'];
|
19 | this.options = [
|
20 | {
|
21 | name: 'search',
|
22 | aliases: ['s'],
|
23 | type: Boolean,
|
24 | default: false,
|
25 | description: 'Search whole angular.io instead of just api.'
|
26 | }
|
27 | ];
|
28 | }
|
29 | validate(options) {
|
30 | if (!options.keyword) {
|
31 | this.logger.error(`keyword argument is required.`);
|
32 | return false;
|
33 | }
|
34 | }
|
35 | run(options) {
|
36 | return __awaiter(this, void 0, void 0, function* () {
|
37 | let searchUrl = `https://angular.io/api?query=${options.keyword}`;
|
38 | if (options.search) {
|
39 | searchUrl = `https://www.google.com/search?q=site%3Aangular.io+${options.keyword}`;
|
40 | }
|
41 | return opn(searchUrl);
|
42 | });
|
43 | }
|
44 | }
|
45 | DocCommand.aliases = ['d'];
|
46 | exports.default = DocCommand;
|
47 |
|
\ | No newline at end of file |