Skip to content

Commit

Permalink
feat(@angular/cli): adding option to search docs as well
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitarora authored and hansl committed May 4, 2017
1 parent aa958a6 commit 5e39361
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 15 additions & 2 deletions packages/@angular/cli/commands/doc.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
const Command = require('../ember-cli/lib/models/command');
import { DocTask } from '../tasks/doc';

export interface DocOptions {
search?: boolean;
}

const DocCommand = Command.extend({
name: 'doc',
description: 'Opens the official Angular documentation for a given keyword.',
works: 'everywhere',
availableOptions: [
{
name: 'search',
aliases: ['s'],
type: Boolean,
default: false,
description: 'Search docs instead of api.'
}
],

anonymousOptions: [
'<keyword>'
],

run: function(_commandOptions: any, rawArgs: Array<string>) {
run: function(commandOptions: DocOptions, rawArgs: Array<string>) {
const keyword = rawArgs[0];

const docTask = new DocTask({
ui: this.ui,
project: this.project
});

return docTask.run(keyword);
return docTask.run(keyword, commandOptions.search);
}
});

Expand Down
6 changes: 4 additions & 2 deletions packages/@angular/cli/tasks/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ const Task = require('../ember-cli/lib/models/task');
const opn = require('opn');

export const DocTask: any = Task.extend({
run: function(keyword: string) {
const searchUrl = `https://angular.io/docs/ts/latest/api/#!?query=${keyword}`;
run: function(keyword: string, search: boolean) {
const searchUrl = search ? `https://angular.io/search/#stq=${keyword}&stp=1` :
`https://angular.io/docs/ts/latest/api/#!?query=${keyword}`;

return opn(searchUrl, { wait: false });
}
});

0 comments on commit 5e39361

Please sign in to comment.