Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorMichael Hutchinson <m.j.hutchinson@gmail.com>2013-08-24 03:35:48 +0400
committerMichael Hutchinson <m.j.hutchinson@gmail.com>2013-08-24 03:35:48 +0400
commit0164e5466e2bd267afef7b4138c03e151e611000 (patch)
treedf5138d48097528e50cb96b6a034df2cef0d072a /main
parent767fe0ef026bb0b7fe88fe3cbfa591a905de5afd (diff)
[mdtool] Initialize addin registry, better args handling
Diffstat (limited to 'main')
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core/ApplicationService.cs15
-rw-r--r--main/src/tools/mdtool/src/mdtool.cs137
2 files changed, 112 insertions, 40 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/ApplicationService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/ApplicationService.cs
index 2ea2fdc669..46698c89d1 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/ApplicationService.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/ApplicationService.cs
@@ -36,16 +36,23 @@ namespace MonoDevelop.Core
{
public int StartApplication (string appId, string[] parameters)
{
+ var app = GetApplication (appId);
+ if (app == null)
+ throw new InstallException ("Application not found: " + appId);
+ return app.Run (parameters);
+ }
+
+ public IApplication GetApplication (string appId)
+ {
ExtensionNode node = AddinManager.GetExtensionNode ("/MonoDevelop/Core/Applications/" + appId);
if (node == null)
- throw new InstallException ("Application not found: " + appId);
+ return null;
- ApplicationExtensionNode apnode = node as ApplicationExtensionNode;
+ var apnode = node as ApplicationExtensionNode;
if (apnode == null)
throw new Exception ("Invalid node type");
- IApplication app = (IApplication) apnode.CreateInstance ();
- return app.Run (parameters);
+ return (IApplication) apnode.CreateInstance ();
}
public IApplicationInfo[] GetApplications ()
diff --git a/main/src/tools/mdtool/src/mdtool.cs b/main/src/tools/mdtool/src/mdtool.cs
index 37bfd7c545..1da5671f2a 100644
--- a/main/src/tools/mdtool/src/mdtool.cs
+++ b/main/src/tools/mdtool/src/mdtool.cs
@@ -34,6 +34,7 @@ using Mono.Addins;
using Mono.Addins.Setup;
using System.IO;
using System.Collections;
+using MonoDevelop.Core.Logging;
public class MonoDevelopProcessHost
{
@@ -41,53 +42,94 @@ public class MonoDevelopProcessHost
{
try {
Runtime.SetProcessName ("mdtool");
-
- if (args.Length == 0 || args [0] == "--help") {
- Console.WriteLine ();
- Console.WriteLine ("MonoDevelop Tool Runner");
- Console.WriteLine ();
- Console.WriteLine ("Usage: mdtool [options] <tool> ... : Runs a tool.");
- Console.WriteLine (" mdtool setup ... : Runs the setup utility.");
- Console.WriteLine (" mdtool -q : Lists available tools.");
- Console.WriteLine ();
- Console.WriteLine ("Options:");
- Console.WriteLine (" --verbose (-v): Enable verbose log.");
- Console.WriteLine ();
- ShowAvailableApps ();
- return 0;
- }
- int pi = 0;
+ EnabledLoggingLevel verbosity = EnabledLoggingLevel.Fatal;
+ bool regUpdate = true;
+ bool listTools = false;
+ bool showHelp = false;
+ bool badInput = false;
- bool verbose = false;
- if (args [0] == "-v" || args [0] == "--verbose") {
+ //read the arguments to mdtool itself
+ int pi = 0;
+ while (pi < args.Length && (args[pi][0] == '-' || args[pi][0] == '/')) {
+ string arg = args[pi];
pi++;
- verbose = true;
+ switch (arg) {
+ case "-v":
+ case "/v":
+ case "--verbose":
+ case "/verbose":
+ verbosity = (EnabledLoggingLevel)((int)verbosity << 1) | EnabledLoggingLevel.Fatal;
+ continue;
+ case "-q":
+ case "/q":
+ listTools = true;
+ continue;
+ case "--no-reg-update":
+ case "/no-reg-update":
+ case "-nru":
+ case "/nru":
+ regUpdate = false;
+ continue;
+ case "-h":
+ case "/h":
+ case "--help":
+ case "/help":
+ showHelp = true;
+ continue;
+ default:
+ Console.Error.WriteLine ("Unknown argument '{0}'", arg);
+ badInput = true;
+ break;
+ }
+ }
+
+ //determine the tool name and arguments
+ string toolName = null;
+ string[] toolArgs = null;
+ if (!showHelp && !listTools && !badInput) {
+ if (pi < args.Length) {
+ toolName = args[pi];
+ toolArgs = new string [args.Length - 1 - pi];
+ Array.Copy (args, pi + 1, toolArgs, 0, args.Length - 1 - pi);
+ } else if (args.Length == 0) {
+ showHelp = true;
+ } else {
+ Console.Error.WriteLine ("No tool specified");
+ badInput = true;
+ }
}
- if (args [0] == "-q") {
- ShowAvailableApps ();
- return 0;
+ //setup app needs to skip runtime initialization or we get addin engine races
+ if (toolName == "setup") {
+ return RunSetup (toolArgs);
}
- string[] newArgs = new string [args.Length - 1 - pi];
- Array.Copy (args, pi + 1, newArgs, 0, args.Length - 1 - pi);
+ // Only log fatal errors unless verbosity is specified. Command line tools should already
+ // be providing feedback using the console.
+ var logger = (ConsoleLogger)LoggingService.GetLogger ("ConsoleLogger");
+ logger.EnabledLevel = verbosity;
+
+ Runtime.Initialize (regUpdate);
- if (args [pi] == "setup") {
- return RunSetup (newArgs);
+ if (showHelp || badInput) {
+ ShowHelp (badInput);
+ return badInput? 1 : 0;
}
- //only init the runtime if not running the setup tool
- Runtime.Initialize (false);
+ var tool = Runtime.ApplicationService.GetApplication (toolName);
+ if (tool == null) {
+ Console.Error.WriteLine ("Tool '{0}' not found.", toolName);
+ listTools = true;
+ badInput = true;
+ }
- // Only log fatal errors unless verbose is specified. Command line tools should already
- // be providing feedback using the console.
- var logger = (MonoDevelop.Core.Logging.ConsoleLogger)LoggingService.GetLogger ("ConsoleLogger");
- logger.EnabledLevel = verbose
- ? MonoDevelop.Core.Logging.EnabledLoggingLevel.UpToWarn
- : MonoDevelop.Core.Logging.EnabledLoggingLevel.UpToFatal;
+ if (listTools) {
+ ShowAvailableTools ();
+ return badInput? 1 : 0;
+ }
- return Runtime.ApplicationService.StartApplication (args [pi], newArgs);
+ return tool.Run (toolArgs);
} catch (UserException ex) {
Console.WriteLine (ex.Message);
return -1;
@@ -102,6 +144,28 @@ public class MonoDevelopProcessHost
}
}
}
+
+ static void ShowHelp (bool shortHelp)
+ {
+ if (shortHelp) {
+ Console.WriteLine ();
+ Console.WriteLine ("Run `mdtool --help` to show usage information.");
+ Console.WriteLine ();
+ return;
+ }
+ Console.WriteLine ();
+ Console.WriteLine ("MonoDevelop Tool Runner");
+ Console.WriteLine ();
+ Console.WriteLine ("Usage: mdtool [options] <tool> ... : Runs a tool.");
+ Console.WriteLine (" mdtool setup ... : Runs the setup utility.");
+ Console.WriteLine (" mdtool -q : Lists available tools.");
+ Console.WriteLine ();
+ Console.WriteLine ("Options:");
+ Console.WriteLine (" --verbose (-v) Increases log verbosity. Can be used multiple times.");
+ Console.WriteLine (" --no-reg-update Skip updating addin registry. Faster but results in");
+ Console.WriteLine (" random errors if registry is not up to date.");
+ ShowAvailableTools ();
+ }
static int RunSetup (string[] args)
{
@@ -118,8 +182,9 @@ public class MonoDevelopProcessHost
return setupTool.Run (args);
}
- static void ShowAvailableApps ()
+ static void ShowAvailableTools ()
{
+ Console.WriteLine ();
Console.WriteLine ("Available tools:");
foreach (IApplicationInfo ainfo in Runtime.ApplicationService.GetApplications ()) {
Console.Write ("- " + ainfo.Id);