Skip to content
Browse files

CLI: Add 'setup' command to install debug token to devices.

  • Loading branch information...
1 parent ae7f75e commit 0ff41a93ed481fef6b455d06f1f8d29e26a6c028 @roblillack committed
Showing with 68 additions and 0 deletions.
  1. +4 −0 tooling/MonoBerry.cs
  2. +63 −0 tooling/Setup.cs
  3. +1 −0 tooling/tool.csproj
View
4 tooling/MonoBerry.cs
@@ -61,6 +61,10 @@ public void Execute (Type cmd, List<string> parameters)
Console.Error.WriteLine ("Unknown command: {0}", cmd);
}
+ public void Execute (Type cmd) {
+ Execute (cmd, new List<string> ());
+ }
+
public T GetCommand<T> ()
{
foreach (object c in commands) {
View
63 tooling/Setup.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+
+namespace MonoBerry.Tool
+{
+ public class Setup : Command
+ {
+ public override string Name {
+ get { return "setup"; }
+ }
+
+ public override string Description {
+ get { return "Install debug token on the specified device."; }
+ }
+
+ public override void Execute (IList<string> parameters)
+ {
+ if (!File.Exists (Application.Configuration.DebugToken)) {
+ Console.WriteLine ("Debug token does not exist. Creating ...");
+ Application.Execute (typeof (CreateToken));
+ }
+
+
+ var dev = GetDevice (parameters);
+ var cmd = String.Format ("{0}/usr/bin/blackberry-nativepackager -installDebugToken {1} -device {2} -password \"{3}\"",
+ Application.Configuration.NativeSDKHostDir,
+ Application.Configuration.DebugToken,
+ dev.IP,
+ dev.Password);
+ Run (cmd);
+ }
+
+ static void Run (string cmd)
+ {
+ try {
+ using (Process proc = Process.Start ("/bin/sh", String.Format ("-c '{0}'", cmd))) {
+ proc.WaitForExit();
+ }
+ } catch (Exception e) {
+ throw new Error (String.Format ("Error running command {0}: {1}", cmd, e.Message));
+ }
+ }
+
+ Device GetDevice (IList<string> parameters)
+ {
+ var devs = Application.Configuration.GetDevices ();
+
+ if (devs.Count == 1) {
+ var e = devs.Values.GetEnumerator ();
+ e.MoveNext ();
+ return e.Current;
+ } else if (devs.Count == 0) {
+ throw new Error ("No devices configured.");
+ } else if (parameters.Count == 1) {
+ return devs [parameters [0]];
+ }
+
+ throw new Error ("Please specify a device.");
+ }
+ }
+}
View
1 tooling/tool.csproj
@@ -57,6 +57,7 @@
<Compile Include="Connect.cs" />
<Compile Include="CreateToken.cs" />
<Compile Include="Shell.cs" />
+ <Compile Include="Setup.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

0 comments on commit 0ff41a9

Please sign in to comment.
Something went wrong with that request. Please try again.