Merge pull request #9714 from Phrohdoh/fix_9713

Fix misleading Utility message.
This commit is contained in:
RoosterDragon
2015-10-24 18:22:55 +01:00

View File

@@ -15,6 +15,16 @@ using OpenRA.FileSystem;
namespace OpenRA.Utility namespace OpenRA.Utility
{ {
public class NoSuchCommandException : Exception
{
public readonly string Command;
public NoSuchCommandException(string command)
: base("No such command '{0}'".F(command))
{
Command = command;
}
}
class Program class Program
{ {
static void Main(string[] args) static void Main(string[] args)
@@ -56,11 +66,12 @@ namespace OpenRA.Utility
try try
{ {
if (!actions.ContainsKey(args[0])) var command = args[0];
throw new ArgumentException(); if (!actions.ContainsKey(command))
throw new NoSuchCommandException(command);
var action = actions[args[0]].Key; var action = actions[command].Key;
var validateActionArgs = actions[args[0]].Value; var validateActionArgs = actions[command].Value;
if (validateActionArgs.Invoke(args)) if (validateActionArgs.Invoke(args))
{ {
@@ -68,8 +79,8 @@ namespace OpenRA.Utility
} }
else else
{ {
Console.WriteLine("Invalid arguments for '{0}'", args[0]); Console.WriteLine("Invalid arguments for '{0}'", command);
GetActionUsage(args[0], action); GetActionUsage(command, action);
} }
} }
catch (Exception e) catch (Exception e)
@@ -78,13 +89,13 @@ namespace OpenRA.Utility
Log.Write("utility", "Received args: {0}", args.JoinWith(" ")); Log.Write("utility", "Received args: {0}", args.JoinWith(" "));
Log.Write("utility", "{0}", e); Log.Write("utility", "{0}", e);
if (e is ArgumentException) if (e is NoSuchCommandException)
Console.WriteLine("No such command '{0}'", args[0]); Console.WriteLine(e.Message);
else else
{ {
Console.WriteLine("Error: Utility application crashed. See utility.log for details"); Console.WriteLine("Error: Utility application crashed. See utility.log for details");
throw; throw;
} }
} }
} }