Skip to content

Commit

Permalink
Merge pull request #209 from IgniteUI/vslavov/66-doc-command
Browse files Browse the repository at this point in the history
feat: add doc command #66
  • Loading branch information
bazal4o authored Mar 8, 2018
2 parents 3a36768 + d19ef81 commit 1445d54
Show file tree
Hide file tree
Showing 8 changed files with 1,131 additions and 276 deletions.
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,29 @@
"bla",
"-g"
]
},{
"type": "node",
"request": "launch",
"name": "Launch DOC Command, No Arguments",
"cwd": "${workspaceRoot}/output",
"program": "${workspaceRoot}/bin/execute.js",
"console": "externalTerminal",
"preLaunchTask": "build",
"args": [
"doc"
]
},{
"type": "node",
"request": "launch",
"name": "Launch DOC Command, Term Alias",
"cwd": "${workspaceRoot}/output",
"program": "${workspaceRoot}/bin/execute.js",
"console": "externalTerminal",
"preLaunchTask": "build",
"args": [
"doc",
"igGrid"
]
}
]
}
14 changes: 14 additions & 0 deletions lib/PromptSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ export class PromptSession {

constructor(private templateManager: TemplateManager) { }

public static async chooseTerm() {
const answers = await inquirer.prompt({
default: null,
message: "Enter a search term",
name: "term",
type: "input"
});
if (answers.term) {
return answers.term;
} else {
const retProm = await this.chooseTerm();
return retProm;
}
}
/**
* Start questions session for project creation
*/
Expand Down
5 changes: 5 additions & 0 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as yargs from "yargs";
import { default as add } from "./commands/add";
import { default as build } from "./commands/build";
import { default as config } from "./commands/config";
import { default as doc } from "./commands/doc";
import { default as generate } from "./commands/generate";
import { default as newCommand } from "./commands/new";
import { default as quickstart } from "./commands/quickstart";
Expand Down Expand Up @@ -33,6 +34,7 @@ export async function run(args = null) {
.command(start)
.command(generate)
.command(config)
.command(doc)
.command(test)
.options({
version: {
Expand Down Expand Up @@ -76,6 +78,9 @@ export async function run(args = null) {
break;
case "config":
break;
case "doc":
await doc.execute(argv);
break;
case "test":
await test.execute(argv);
break;
Expand Down
39 changes: 39 additions & 0 deletions lib/commands/doc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as opn from "opn";
import { PromptSession } from "../PromptSession";
import { Util } from "../Util";

let doc: {
[term: string]: any,
execute: (argv: any) => Promise<void>
};
doc = {
// tslint:disable:object-literal-sort-keys
command: "doc [term]",
desc: "opens the Infragistics search for the given term",
builder: {
term: {
describe: "The term you would like to search for",
type: "string"
}
},
template: null,
open(target) {
opn(target);
},
async execute(argv) {
if (!argv.term) {
const answer = await PromptSession.chooseTerm();
argv.term = answer;
await this.execute(argv);
} else if (!Util.isAlphanumericExt(argv.term)) {
return Util.error(`The search term '${argv.term}' is not valid.` + "\n" +
"Name should start with a letter and can also contain numbers, dashes and spaces.",
"red");
} else {
Util.log(`Review your search results in the browser`, "green");
doc.open(`https://www.infragistics.com/search?q=${argv.term.trim()}`);
}
}
};

export default doc;
Loading

0 comments on commit 1445d54

Please sign in to comment.