/// <summary> /// Creates the argument processor associated with the provided command line argument. /// The Lazy that is returned will initialize the underlying argument processor when it is first accessed. /// </summary> /// <param name="argument">Command line argument to create the argument processor for.</param> /// <returns>The argument processor or null if one was not found.</returns> public IArgumentProcessor CreateArgumentProcessor(string argument) { if (String.IsNullOrWhiteSpace(argument)) { throw new ArgumentException("Cannot be null or empty", nameof(argument)); } Contract.EndContractBlock(); // Parse the input into its command and argument parts. var pair = new CommandArgumentPair(argument); // Find the associated argument processor. IArgumentProcessor argumentProcessor; CommandToProcessorMap.TryGetValue(pair.Command, out argumentProcessor); // If an argument processor was not found for the command, then consider it as a test source argument. if (argumentProcessor == null) { // Update the command pair since the command is actually the argument in the case of // a test source. pair = new CommandArgumentPair(TestSourceArgumentProcessor.CommandName, argument); argumentProcessor = SpecialCommandToProcessorMap[TestSourceArgumentProcessor.CommandName]; } if (argumentProcessor != null) { argumentProcessor = WrapLazyProcessorToInitializeOnInstantiation(argumentProcessor, pair.Argument); } return(argumentProcessor); }
/// <summary> /// Creates the argument processor associated with the provided command line argument. /// The Lazy that is returned will initialize the underlying argument processor when it is first accessed. /// </summary> /// <param name="command">Command name of the argument processor.</param> /// <param name="arguments">Command line arguments to create the argument processor for.</param> /// <returns>The argument processor or null if one was not found.</returns> public IArgumentProcessor CreateArgumentProcessor(string command, string[] arguments) { if (arguments == null || arguments.Length == 0) { throw new ArgumentException("Cannot be null or empty", nameof(arguments)); } Contract.EndContractBlock(); // Find the associated argument processor. IArgumentProcessor argumentProcessor; CommandToProcessorMap.TryGetValue(command, out argumentProcessor); if (argumentProcessor != null) { argumentProcessor = WrapLazyProcessorToInitializeOnInstantiation(argumentProcessor, arguments); } return(argumentProcessor); }