forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.ts
More file actions
43 lines (36 loc) · 1.07 KB
/
doc.ts
File metadata and controls
43 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// tslint:disable:no-global-tslint-disable file-header
import { Command } from '../models/command';
const opn = require('opn');
export interface Options {
keyword: string;
search?: boolean;
}
export default class DocCommand extends Command {
public readonly name = 'doc';
public readonly description = 'Opens the official Angular API documentation for a given keyword.';
public static aliases = ['d'];
public readonly arguments = ['keyword'];
public readonly options = [
{
name: 'search',
aliases: ['s'],
type: Boolean,
default: false,
description: 'Search whole angular.io instead of just api.',
},
];
public validate(options: Options) {
if (!options.keyword) {
this.logger.error(`keyword argument is required.`);
return false;
}
return true;
}
public async run(options: Options) {
let searchUrl = `https://angular.io/api?query=${options.keyword}`;
if (options.search) {
searchUrl = `https://www.google.com/search?q=site%3Aangular.io+${options.keyword}`;
}
return opn(searchUrl);
}
}