public bool ParseCommandLine(string[] args)
{
// Help requested? (by default, no)
bool help = false;
// Definition of the command-line arguments and how to set the related configuration data
var options = new OptionSet()
{
{ "intercept=", "Intercept or forward requests", (bool o) => Intercept = o },
{ "log=", "Level of messages to log", (LogLevel o) => Level = o },
{ "config=", "Configuration file", (string o) => ConfigFile = o },
{ "default", "Generate a default configuration", o => DefaultConfig = o != null },
{ "h|help", "Show this message", o => help = o != null }
};
try
{
// Parse the command-line arguments (thanks NDesk!)
List<string> extra = options.Parse(args);
// If there are some arguments not parsed, no name of pipe or an invalid port number, show the help
if(extra.Count > 0)
{
Console.WriteLine("Unknow parameter: {0}", extra[0]);
Console.WriteLine();
ShowHelp(options);
return false; // Do not continue the application
}
}
catch(OptionException e)
{
// Something wrong with the arguments
Console.WriteLine(e.Message);
Console.WriteLine("Try 'ADVinterceptor --help' for more information.");
return false;
}
// Show the help?
if(help)
{
ShowHelp(options);
return false;
}
// Continue the application
return true;
}