예제 #1
0
        public static CommandLineParameters Parse(string[] args)
        {
            var clp = new CommandLineParameters();

            clp.DoParse(args);
            return(clp);
        }
예제 #2
0
        /// <summary>
        /// Parses the specified string arguments into a new instance of the Options class.
        /// </summary>
        /// <param name="args">The arguments to parse.</param>
        /// <returns>A new instance of the Options class initialized from the specidifed string arguments</returns>
        /// <exception cref="ArgumentException">There is an error parsing an argument.</exception>
        public static Options Parse(string[] args)
        {
            var parameters = CommandLineParameters.Parse(args);

            var options = CreateOptions(parameters);

            CheckForInvalidParameters(parameters);

            return(options);
        }
예제 #3
0
        private static void CheckForInvalidParameters(CommandLineParameters parameters)
        {
            if (parameters.Named.Count > 0)
            {
                foreach (var name in parameters.Named.Keys)
                {
                    throw new ArgumentException("Invalid option /" + name);
                }
            }

            if (parameters.Positionals.Count > 0)
            {
                throw new ArgumentException(string.Format("Invalid argument \"{0}\"", parameters.Positionals[0]));
            }
        }
예제 #4
0
파일: Options.cs 프로젝트: helgihaf/Grocker
        private static void CheckForInvalidParameters(CommandLineParameters parameters)
        {
            if (parameters.Named.Count > 0)
            {
                foreach (var name in parameters.Named.Keys)
                {
                    throw new ArgumentException("Invalid option /" + name);
                }
            }

            if (parameters.Positionals.Count > 0)
            {
                throw new ArgumentException(string.Format("Invalid argument \"{0}\"", parameters.Positionals[0]));
            }
        }
예제 #5
0
파일: Options.cs 프로젝트: helgihaf/Grocker
        private static Options CreateOptions(CommandLineParameters parameters)
        {
            var options = new Options();
            options.HelpWanted = parameters.DetachNamedBool("?");
            if (options.HelpWanted)
            {
                return options;
            }

            options.DirectoryPath = parameters.DetachPositional();
            options.Filter = parameters.DetachNamed("f");
            options.EnableColorSchema = !parameters.DetachNamedBool("nc");
            options.ColorSchemaName = parameters.DetachNamed("c");
            if (!options.EnableColorSchema && !string.IsNullOrEmpty(options.ColorSchemaName))
            {
                throw new ArgumentException("Options nc and c are incompatible with each other");
            }

            return options;
        }
예제 #6
0
        private static Options CreateOptions(CommandLineParameters parameters)
        {
            var options = new Options();

            options.HelpWanted = parameters.DetachNamedBool("?");
            if (options.HelpWanted)
            {
                return(options);
            }

            options.DirectoryPath     = parameters.DetachPositional();
            options.Filter            = parameters.DetachNamed("f");
            options.EnableColorSchema = !parameters.DetachNamedBool("nc");
            options.ColorSchemaName   = parameters.DetachNamed("c");
            if (!options.EnableColorSchema && !string.IsNullOrEmpty(options.ColorSchemaName))
            {
                throw new ArgumentException("Options nc and c are incompatible with each other");
            }

            return(options);
        }
예제 #7
0
 public static CommandLineParameters Parse(string[] args)
 {
     var clp = new CommandLineParameters();
     clp.DoParse(args);
     return clp;
 }