private int Execute(string[] args) { var result = 0; try { var clh = new CmdLineHandler(); SetUpCommandLineOptions(clh); clh.Evaluate(args); if( ! clh.IsValid() ) { PrintUsage(); result = 1; } else if(HelpNeeded(clh)) { PrintUsage(); result = 0; } else { IRecipe recipe = null; if(clh.HasOption("recipe")) { if( clh.HasOption("assembly")) { Console.WriteLine("Option 'recipe' present, ignoring option 'assembly'."); } recipe = RecipeFactory.Load(clh.GetOptionValueFor("recipe")); if( recipe == null ) { Console.WriteLine(String.Format( "Couldn't read recipe at location '{0}'.", clh.GetOptionValueFor("recipe"))); result = 1; } } else if(clh.HasOption("assembly")) { var filePathName = clh.GetOptionValueFor("assembly"); if(File.Exists(filePathName)) { recipe = RecipeFactory.NewRecipe(string.Empty); recipe.AddAssembly(filePathName); } else { Console.WriteLine("Error: Couldn't read assembly at location '{0}'.", filePathName); PrintUsage(); result = 1; } } if( recipe != null && result == 0 ) { result = ExecuteValidCommandLine(clh, recipe); } } } catch(Exception ex) { while(ex.InnerException != null) { ex = ex.InnerException; } Console.WriteLine("Internal error: " + ex.Message); Console.WriteLine(ex.StackTrace); result = 1; } Console.WriteLine("Done."); return result; }
private static CmdLineHandler SetUpCommandLineHandler(string[] args) { var clh = new CmdLineHandler(); clh.AcceptOption("autoexit", false); clh.AcceptOption("autorun", false); clh.AcceptOption("assembly", true); clh.AcceptOption("recipe", true); clh.AcceptOption("xml", false); clh.AcceptOption("?", false); clh.AcceptOption("help", false); clh.AcceptOption("nodialogs", false); // hidden option so we can automatically test invalid command line // arguments [23aug09, ml] clh.Evaluate(args); return clh; }