Skip to content

Commit 9ad5672

Browse files
Fatme HavaluovaFatme Havaluova
authored andcommitted
Help command
1 parent fb6df7c commit 9ad5672

File tree

4 files changed

+94
-6
lines changed

4 files changed

+94
-6
lines changed

lib/command-executor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ export class CommandExecutor implements ICommandExecutor {
1919

2020
private executeCore(commandName: string, commandArguments: string[]): IFuture<void> {
2121
return (() => {
22-
var command: ICommand = new (require("./commands/" + commandName).Command)();
23-
if(!command) {
24-
errors.fail("Unable to resolve commandName %s", commandName);
25-
}
26-
2722
try {
23+
var command: ICommand = new (require("./commands/" + commandName).Command)();
24+
if(!command) {
25+
errors.fail("Unable to resolve commandName %s", commandName);
26+
}
27+
2828
command.execute(commandArguments).wait();
2929
} catch(e) {
3030
if(options.debug) {

lib/commands/help.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
///<reference path=".././.d.ts"/>
2+
"use strict";
3+
4+
import fs = require("fs");
5+
import path = require("path");
6+
import util = require("util");
7+
8+
export class Command implements ICommand {
9+
public execute(args: string[]): IFuture<void> {
10+
return (() => {
11+
var topic = (args[0] || "").toLowerCase();
12+
if (topic === "help") {
13+
topic = "";
14+
}
15+
16+
var helpContent = fs.readFileSync(path.join(__dirname, "../../resources/help.txt")).toString();
17+
18+
var pattern = util.format("--\\[%s\\]--((.|[\\r\\n])+?)--\\[/\\]--", this.escape(topic));
19+
var regex = new RegExp(pattern);
20+
var match = regex.exec(helpContent);
21+
if (match) {
22+
var helpText = match[1].trim();
23+
console.log(helpText);
24+
}
25+
}).future<void>()();
26+
}
27+
28+
private escape(s: string): string {
29+
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
30+
}
31+
}

lib/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ var knownOptions: any = {
1010
"stdout": String,
1111
"stderr": String,
1212
"env": String,
13-
"args": String
13+
"args": String,
14+
"help": Boolean
1415
};
1516

1617
var parsed = {};

resources/help.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--[]--
2+
3+
Usage:
4+
$ ios-sim-portable <command> [command parameters] [--command <options>]
5+
6+
General commands:
7+
help <command> Shows additional information about the commands in this list.
8+
launch <App path> Launch the application at the specified path on the iOS Simulator.
9+
device-types Lists the available device types for current Xcode version.
10+
sdks Lists the available iOS sdk versions.
11+
12+
General options:
13+
--help Prints help about the selected command.
14+
15+
--[/]--
16+
17+
--[help]--
18+
19+
Usage:
20+
$ ios-sim-portable help [<Command>]
21+
22+
Lists the available commands or shows information about the selected command.
23+
<Command> is any of the available commands as listed by $ ios-sim-portable help.
24+
25+
--[/]--
26+
27+
--[launch]--
28+
29+
Usage:
30+
$ ios-sim-portable launch <App path> [--exit]
31+
32+
Launch the application at the specified path on iOS Simulator.
33+
<App path> - Specifies the path to application(.app file) that you want to run in iOS Simulator.
34+
35+
Options:
36+
--exit - If this option is specified, the process is exited after the iOS Simulator is started.
37+
38+
--[/]--
39+
40+
--[device-types]--
41+
42+
Usage:
43+
$ ios-sim-portable device-types
44+
45+
Lists the available device types for current XCode version
46+
47+
--[/]--
48+
49+
--[sdks]--
50+
51+
Usage:
52+
$ ios-sim-portable sdks
53+
54+
Lists the available iOS sdk versions.
55+
56+
--[/]--

0 commit comments

Comments
 (0)