Skip to content

Commit 877825e

Browse files
FatmeFatme
authored andcommitted
Merge pull request #3 from telerik/fatme/commands
Missing options and commands
2 parents 2abd6ce + 9ad5672 commit 877825e

File tree

7 files changed

+163
-9
lines changed

7 files changed

+163
-9
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/commands/sdks.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
///<reference path=".././.d.ts"/>
2+
"use strict";
3+
import iphoneSimulatorLibPath = require("./../iphone-simulator");
4+
5+
export class Command implements ICommand {
6+
public execute(args: string[]): IFuture<void> {
7+
var iphoneSimulator = new iphoneSimulatorLibPath.iPhoneSimulator();
8+
return iphoneSimulator.printSDKS();
9+
}
10+
}

lib/declarations.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
interface IiPhoneSimulator {
55
run(appName: string): IFuture<void>;
6-
printDeviceTypes(): void;
6+
printDeviceTypes(): IFuture<void>;
7+
printSDKS(): IFuture<void>;
78
}
89

910
interface ICommand {
@@ -32,4 +33,11 @@ interface ISimulator {
3233
interface IExecuteOptions {
3334
canRunMainLoop: boolean;
3435
appPath?: string;
36+
}
37+
38+
interface ISdk {
39+
displayName: string;
40+
version: string;
41+
rootPath: string;
42+
sdkInfo(): string;
3543
}

lib/iphone-simulator.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import child_process = require("child_process");
55
import fs = require("fs");
66
import Future = require("fibers/future");
7+
import os = require("os");
78
import path = require("path");
89
import util = require("util");
910

@@ -35,7 +36,6 @@ export class iPhoneSimulator implements IiPhoneSimulator {
3536
}
3637

3738
public printDeviceTypes(): IFuture<void> {
38-
3939
var action = () => {
4040
var simulator = this.createSimulator();
4141
_.each(simulator.validDeviceIdentifiers, (identifier: any) => console.log(identifier));
@@ -44,6 +44,30 @@ export class iPhoneSimulator implements IiPhoneSimulator {
4444
return this.execute(action, { canRunMainLoop: false });
4545
}
4646

47+
public printSDKS(): IFuture<void> {
48+
var action = () => {
49+
var systemRootClass = this.getClassByName("DTiPhoneSimulatorSystemRoot");
50+
var roots = systemRootClass("knownRoots");
51+
var count = roots("count");
52+
53+
var sdks: ISdk[] = [];
54+
for(var index=0; index < count; index++) {
55+
var root = roots("objectAtIndex", index);
56+
57+
var displayName = root("sdkDisplayName").toString();
58+
var version = root("sdkVersion").toString();
59+
var rootPath = root("sdkRootPath").toString();
60+
61+
sdks.push(new Sdk(displayName, version, rootPath));
62+
}
63+
64+
sdks = _.sortBy(sdks, (sdk: ISdk) => sdk.version);
65+
_.each(sdks, (sdk: ISdk) => console.log(sdk.sdkInfo() + os.EOL));
66+
};
67+
68+
return this.execute(action, { canRunMainLoop: false });
69+
}
70+
4771
private execute(action: (appPath?: string) => any, opts: IExecuteOptions): IFuture<void> {
4872
return (() => {
4973
$.importFramework(iPhoneSimulator.FOUNDATION_FRAMEWORK_NAME);
@@ -74,8 +98,11 @@ export class iPhoneSimulator implements IiPhoneSimulator {
7498
iPhoneSimulator.logSessionInfo(error, "Session ended without errors.", "Session ended with error ");
7599
process.exit(0);
76100
});
77-
sessionDelegate.addMethod("session:didStart:withError:", "v@:@c@", function(self: any, sel: any, sess: any, did: any, error:any) {
101+
sessionDelegate.addMethod("session:didStart:withError:", "v@:@c@", function(self: any, sel: string, session: any, started: boolean, error:any) {
78102
iPhoneSimulator.logSessionInfo(error, "Session started without errors.", "Session started with error ");
103+
if(options.exit) {
104+
process.exit(0);
105+
}
79106
});
80107
sessionDelegate.register();
81108

@@ -95,6 +122,14 @@ export class iPhoneSimulator implements IiPhoneSimulator {
95122
}
96123
simulator.setSimulatedDevice(config);
97124

125+
if(options.stderr) {
126+
config("setSimulatedApplicationStdErrPath", $(options.stderr));
127+
}
128+
129+
if(options.stdout) {
130+
config("setSimulatedApplicationStdOutPath", $(options.stdout));
131+
}
132+
98133
config("setLocalizedClientName", $("ios-sim-portable"));
99134

100135
var sessionError: any = new Buffer("");
@@ -196,4 +231,16 @@ export class iPhoneSimulator implements IiPhoneSimulator {
196231

197232
return simulator;
198233
}
234+
}
235+
236+
class Sdk implements ISdk {
237+
constructor(public displayName: string,
238+
public version: string,
239+
public rootPath: string) { }
240+
241+
public sdkInfo(): string {
242+
return [util.format(" Display Name: %s", this.displayName),
243+
util.format(" Version: %s", this.version),
244+
util.format(" Root path: %s", this.rootPath)].join(os.EOL);
245+
}
199246
}

lib/options.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ var yargs = require("yargs");
55

66
var knownOptions: any = {
77
"debug": Boolean,
8+
"exit": Boolean,
89
"device": String,
910
"stdout": String,
1011
"stderr": String,
1112
"env": String,
12-
"args": String
13+
"args": String,
14+
"help": Boolean
1315
};
1416

1517
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)