Пример #1
0
        /// <summary>
        /// Get a string representing the usage of the arguments.
        /// </summary>
        /// <returns></returns>
        public string GetUsage(string appName)
        {
            if (Schema.IsEmpty)
            {
                return("Argument definitions are not present.");
            }

            string usage = ArgsUsage.Build(appName, Schema.Items, Prefix, Separator);

            return(usage);
        }
Пример #2
0
        /// <summary>
        /// Get usage on how to use the supported arguments are used.
        /// </summary>
        /// <returns></returns>
        public string GetUsage(string appName)
        {
            if (Supported == null || Supported.Count == 0)
            {
                return("Argument definitions are not present.");
            }

            string usage = ArgsUsage.Build(appName, Supported, Prefix, Separator);

            return(usage);
        }
Пример #3
0
        /// <summary>
        /// Validate and accept the arguments.
        /// Assumes that the
        /// </summary>
        /// <param name="args"></param>
        /// <param name="prefix">--</param>
        /// <param name="keyValueSeperator">=</param>
        /// <param name="argDefs">The list of argument definitions</param>
        /// <returns></returns>
        public static BoolMessageItem <Args> Accept(string[] rawArgs, string prefix, string keyValueSeperator,
                                                    int minArgs, List <ArgAttribute> supported, List <string> examples)
        {
            Args args = new Args(rawArgs, supported);

            if (args.IsEmpty)
            {
                Console.WriteLine("No arguments were supplied." + Environment.NewLine);
                ArgsUsage.Show(supported, examples);
                return(new BoolMessageItem <Args>(args, false, "No arguments were supplied."));
            }

            // Try to validate and accept the arguments.
            BoolMessageItem <Args> result = Args.Parse(rawArgs, prefix, keyValueSeperator, supported);

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Parse the arguments and checks for named arguments and non-named arguments.
        /// Applies the arguments to the properties of the argument reciever <paramref name="argReciever"/>.
        /// If there were errors during the parsing, logs what arguments are required.
        /// </summary>
        /// <param name="rawArgs">e.g. "-config:prod.xml", "-date:T-1", "DefaultSettings01"</param>
        /// <param name="prefix">Character used to identifiy the name
        /// of a named parameter. e.g. "-" as in "-config:prod.xml"
        /// Leave null or string.emtpy to indicate there is no prefix.
        /// In which case, only the <paramref name="separator"/> is used to distinguish
        /// namevalue pairs.</param>
        /// <param name="separator">Character used to separate the named
        /// argument with it's value in a named argument. e.g. ":" as in "-config:prod.xml"
        /// If this is null or string.empty, in addition to the <paramref name="prefix"/></param>
        /// <param name="argumentsStore">Object to store the named arguments.</param>
        /// <returns>True if arguments are valid, false otherwise. argsReciever contains the arguments.</returns>
        public static bool Accept(string[] rawArgs, string prefix, string separator, object argsReciever)
        {
            Args args = new Args(rawArgs, prefix, separator);

            if (args.IsHelp)
            {
                Console.WriteLine(ArgsUsage.Build(argsReciever));
                return(false);
            }

            // Parse the command line arguments.
            BoolMessageItem <Args> results = Args.Parse(rawArgs, prefix, separator, argsReciever);

            if (!results.Success)
            {
                Console.WriteLine("ERROR: Invalid arguments supplied.");
                Console.WriteLine(results.Message);
                Console.WriteLine(ArgsUsage.Build(argsReciever));
                return(false);
            }
            return(true);
        }