/// <summary> /// Parsea la ruta al directorio. /// </summary> /// <param name="startIndex">Índice en el que /// comienza el argumento.</param> /// <returns>Resultados del parseo.</returns> private PathParseResult ParsePathArgument(int startIndex) { var path = _args[startIndex]; if (!path.StartsWith("--")) { var pathValidation = _pathValidator.ValidatePath(path, true); if (pathValidation.Valid) { return(new PathParseResult { Path = path, NextIndex = startIndex + 1 }); } else { throw new ArgumentParseException(pathValidation.Reason); } } else { return(new PathParseResult { Path = Directory.GetCurrentDirectory(), NextIndex = startIndex }); } }
/// <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); }