Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
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);
        }