/// <summary> /// get CommandLineOptions, return error message /// </summary> private static void GetCommandLineOptions(string[] args, out LocBamlOptions options, out string errorMessage) { CommandLine commandLine; try{ // "*" means the option must have a value. no "*" means the option can't have a value commandLine = new CommandLine(args, new string[]{ "parse", // /parse for update "generate", // /generate for generate "*out", // /out for output .csv|.txt when parsing, for output directory when generating "*culture", // /culture for culture name "*translation", // /translation for translation file, .csv|.txt "*asmpath", // /asmpath, for assembly path to look for references (TODO: add asmpath support) "nologo", // /nologo for not to print logo "help", // /help for help "verbose" // /verbose for verbose output } ); } catch (ArgumentException e) { errorMessage = e.Message; options = null; return; } if (commandLine.NumArgs + commandLine.NumOpts < 1) { PrintLogo(null); PrintUsage(); errorMessage = null; options = null; return; } options = new LocBamlOptions(); options.Input = commandLine.GetNextArg(); Option commandLineOption; while ( (commandLineOption = commandLine.GetNextOption()) != null) { if (commandLineOption.Name == "parse") { options.ToParse = true; } else if (commandLineOption.Name == "generate") { options.ToGenerate = true; } else if (commandLineOption.Name == "nologo") { options.HasNoLogo = true; } else if (commandLineOption.Name == "help") { // we print usage and stop processing PrintUsage(); errorMessage = null; options = null; return; } else if (commandLineOption.Name == "verbose") { options.IsVerbose = true; } // the following ones need value else if (commandLineOption.Name == "out") { options.Output = commandLineOption.Value; } else if (commandLineOption.Name == "translation") { options.Translations = commandLineOption.Value; } else if (commandLineOption.Name == "asmpath") { if (options.AssemblyPaths == null) { options.AssemblyPaths = new ArrayList(); } options.AssemblyPaths.Add(commandLineOption.Value); } else if (commandLineOption.Name == "culture") { try { options.CultureInfo = new CultureInfo(commandLineOption.Value); } catch (ArgumentException e) { // Error errorMessage = e.Message; return; } } else { // something that we don't recognize errorMessage = StringLoader.Get("Err_InvalidOption", commandLineOption.Name); return; } } // we passed all the test till here. Now check the combinations of the options errorMessage = options.CheckAndSetDefault(); }