Ejemplo n.º 1
0
        /// <summary>
        /// Parsea el argumento de exclude.
        /// </summary>
        /// <param name="startIndex">Índice en el que
        /// comienza el argumento.</param>
        /// <returns>Resultados del parseo.</returns>
        private ExcludeParseResult ParseExcludeArgument(int startIndex)
        {
            var header  = startIndex;
            var exclude = _args[++header];

            var exclusions = exclude.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (exclusions.Length > 0)
            {
                var results = new ExcludeParseResult
                {
                    Exclude   = exclusions.Select(e => e.Trim()),
                    NextIndex = header
                };

                return(results);
            }

            throw new ArgumentParseException("Badformed --exclude argument. It should have this format: \"EXCLUDE1, EXCLUDE2...\"");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parsea los argumentos de entrada y configura
        /// una búsqueda acorde con ellos.
        /// </summary>
        /// <param name="args">Argumentos de entrada.</param>
        /// <returns>Configuración de renombrado.</returns>
        public RenamingConfiguration Parse()
        {
            int             i          = 0;
            PathParseResult pathResult = ParsePathArgument(i);

            i = pathResult.NextIndex;

            ChangeParseResult  changeResult  = null;
            ExcludeParseResult excludeResult = null;

            for (; i < _args.Length; i++)
            {
                var arg = _args[i];

                if (arg.StartsWith("--"))
                {
                    var parsingArgument = arg
                                          .Substring(2)
                                          .ToLowerInvariant();

                    switch (parsingArgument)
                    {
                    case "change":
                        changeResult = ParseChangeArgument(i);
                        i            = changeResult.NextIndex;
                        break;

                    case "exclude":
                        excludeResult = ParseExcludeArgument(i);
                        i             = excludeResult.NextIndex;
                        break;

                    default:
                        throw new ArgumentParseException(string.Format("Argument \"{0}\" not recognized", arg));
                    }
                }
                else
                {
                    throw new ArgumentParseException("Badformed argument list");
                }
            }

            if (changeResult == null)
            {
                throw new ArgumentParseException("--change argument is required");
            }

            Search search;

            if (excludeResult == null)
            {
                search = new Search(pathResult.Path);
            }
            else
            {
                search = new Search(pathResult.Path, excludeResult.Exclude);
            }

            return(new RenamingConfiguration
            {
                PreparedSearch = search,
                From = changeResult.From,
                To = changeResult.To
            });
        }