internal static ConfiguredCommand ParseArgs(string[] args, IParser parser, ILogger logger = null, bool ignoreInvalidOptions = false) { var usageMessage = Lazy.Create(() => "Usage:" + Environment.NewLine + Usage()); if (args.Length == 0) { throw new ArgumentException(Inv("Command is required. {0}", usageMessage.Value)); } var argsQueue = new Queue <string>(args); string cmdName = argsQueue.Dequeue(); if (!Commands.TryGetValue(cmdName, out Command cmd)) { throw new ArgumentException(Inv("No command '{0}' is found. {1}", cmdName, usageMessage.Value)); } var sw = Stopwatch.StartNew(); Config conf = Config.ParseCommandLineArgs(cmd.Options, argsQueue, parser, caseInsensitive: true, ignoreInvalidOptions: ignoreInvalidOptions); var parseTime = sw.Elapsed; logger = logger ?? new ConsoleLogger(Verbose.GetValue(conf), Daemon.DropDLogPrefix); logger.Verbose("Parsing command line arguments done in {0}", parseTime); return(new ConfiguredCommand(cmd, conf, logger)); }
/// <summary> /// Parses a list of arguments and returns a ConfiguredCommand. /// </summary> public static ConfiguredCommand ParseArgs(string[] args, IParser parser, IIpcLogger logger = null, bool ignoreInvalidOptions = false) { var usageMessage = Lazy.Create(() => "Usage:" + Environment.NewLine + Usage()); if (args.Length == 0) { throw new ArgumentException(I($"Command is required. {usageMessage.Value}")); } var argsQueue = new Queue <string>(args.Length); foreach (var arg in args) { if (arg[0] == ResponseFilePrefix) { foreach (var argFromFile in ProcessResponseFile(arg, parser)) { argsQueue.Enqueue(argFromFile); } } else { argsQueue.Enqueue(arg); } } string cmdName = argsQueue.Dequeue(); if (!Commands.TryGetValue(cmdName, out Command cmd)) { throw new ArgumentException(I($"No command '{cmdName}' is found. {usageMessage.Value}")); } var sw = Stopwatch.StartNew(); Config conf = BuildXL.Utilities.CLI.Config.ParseCommandLineArgs(cmd.Options, argsQueue, parser, caseInsensitive: true, ignoreInvalidOptions: ignoreInvalidOptions); var parseTime = sw.Elapsed; logger = logger ?? new ConsoleLogger(Verbose.GetValue(conf), ServicePipDaemon.LogPrefix); logger.Verbose("Parsing command line arguments done in {0}", parseTime); return(new ConfiguredCommand(cmd, conf, logger)); }