/// <summary> /// Parsea los argumentos introducidos por el usuario. /// </summary> /// <param name="args">Argumentos introducidos.</param> /// <returns>Búsqueda configurada acorde con los /// parámetros.</returns> private static Search ParseArguments(string[] args) { if (args.Length != 3 && args.Length != 4) { throw new ArgumentException("Arguments not specified correctly."); } var path = args[0]; var pathValidator = new PathValidator(); var pathResult = pathValidator.ValidatePath(path, true); if (!pathResult.Valid) { throw new ArgumentException(pathResult.Reason); } var from = args[1]; var fromResult = pathValidator.ValidateFileName(from); if (!fromResult.Valid) { throw new ArgumentException(pathResult.Reason); } var to = args[2]; var toResult = pathValidator.ValidateFileName(to); if (!toResult.Valid) { throw new ArgumentException(pathResult.Reason); } Search search = null; if (args.Length == 4) { var exclusions = args[3].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var exclusionsTrimmed = new List <string>(); foreach (var exclusion in exclusions) { var exclusionTrimmed = exclusion.Trim(); var exclusionResult = pathValidator.ValidatePath(exclusionTrimmed, false); if (!exclusionResult.Valid) { throw new ArgumentException(string.Format("Exclusion \"{0}\" is not a valid filename.", exclusion)); } else { exclusionsTrimmed.Add(exclusionTrimmed); } } search = new Search(path, exclusionsTrimmed); } else { search = new Search(path); } return(search); }
/// <summary> /// Crea una nueva instancia de ArgumentParser. /// </summary> /// <param name="args">Argumentos a parsear.</param> public ArgumentParser(string[] args) { _args = args; _pathValidator = new PathValidator(); }