public bool Invoke(string commandLine)
{
var cmdLine = commandLine;
var regex = new Regex(@"^((""[^""]*"")|(\S+))");
var match = regex.Match(cmdLine);
var name = match.Value.Trim(new char[] { '\"', });
if (File.Exists(name) == true)
name = Process.GetCurrentProcess().ProcessName;
if (this.name != name)
throw new ArgumentException(string.Format(Resources.InvalidCommandName_Format, name));
cmdLine = cmdLine.Substring(match.Length).Trim();
match = regex.Match(cmdLine);
var method = match.Value;
var arguments = cmdLine.Substring(match.Length).Trim();
if (string.IsNullOrEmpty(method) == true)
{
this.PrintSummary();
return false;
}
else if (method == this.HelpName)
{
if (arguments == string.Empty)
this.PrintMethodUsage();
else
this.PrintMethodUsage(arguments);
return false;
}
else if (method == this.VersionName)
{
this.PrintVersion();
return false;
}
else
{
var descriptor = CommandDescriptor.GetMethodDescriptor(this.instance, method);
if (descriptor == null || this.IsMethodVisible(descriptor) == false)
throw new CommandNotFoundException(method);
var switches = descriptor.Switches.Where(item => this.IsSwitchVisible(item));
Invoke(this.instance, arguments, descriptor.MethodInfo, switches);
return true;
}
}