public override void Execute() { base.Execute(); List <string> singleOptionList = PrettifyXmlOptions.GetSingleOptions(); CommandLineOptions cloptions = CommandLineParser.Parse(Arguments.ToArray <string>(), singleOptionList.ToArray()); options = ParseOptions(cloptions); CheckOptions(options); if (options.IsSetHelp) { RaiseCommandLineUsage(this, PrettifyXmlOptions.Usage); } else if (options.IsSetVersion) { RaiseCommandLineUsage(this, Version); } else { StartPrettifyXml(); } Terminate(); }
private static PrettifyXmlCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions) { if (commandLineOptions == null) { throw new CommandLineException(string.Format(CultureInfo.CurrentCulture, "Option used in invalid context -- {0}", "must specify a directory.")); } PrettifyXmlCommandLineOptions targetOptions = new PrettifyXmlCommandLineOptions(); if (commandLineOptions.Arguments.Count > 0) { foreach (var arg in commandLineOptions.Arguments.Keys) { PrettifyXmlOptionType optionType = PrettifyXmlOptions.GetOptionType(arg); if (optionType == PrettifyXmlOptionType.None) { throw new CommandLineException( string.Format(CultureInfo.CurrentCulture, "Option used in invalid context -- {0}", string.Format(CultureInfo.CurrentCulture, "cannot parse the command line argument : [{0}].", arg))); } switch (optionType) { case PrettifyXmlOptionType.InputDirectory: targetOptions.InputDirectory = commandLineOptions.Arguments[arg]; break; case PrettifyXmlOptionType.Help: targetOptions.IsSetHelp = true; break; case PrettifyXmlOptionType.Version: targetOptions.IsSetVersion = true; break; } } } if (commandLineOptions.Parameters.Count > 0) { if (string.IsNullOrEmpty(targetOptions.InputDirectory)) { targetOptions.InputDirectory = commandLineOptions.Parameters.First(); } } // set default the current directory if (string.IsNullOrEmpty(targetOptions.InputDirectory)) { targetOptions.InputDirectory = @"."; } return(targetOptions); }