Example #1
0
        public IConfiguration Parse(string[] argv)
        {
            string firstWord = (argv.Length > 0) ? argv[0] : string.Empty;

            IConfiguration result = this.ParseSubCommand(firstWord, argv);

            CLILogs.CreateLoggers();
            return(result);
        }
Example #2
0
        /// <summary>
        /// Print the CommandLine help.
        /// </summary>
        /// <param name="parser">Parser used (CommandLine).</param>
        /// <param name="errs">Error list.</param>
        /// <param name="argv">argv list.</param>
        /// <typeparam name="T">The generic type parameter: Object to parser to get the usage.</typeparam>
        /// <returns>String usage.</returns>
        public string PrintHelp <T>(CommandLine.ParserResult <T> parser, System.Collections.Generic.IEnumerable <CommandLine.Error> errs, string[] argv)
        {
            // create logs if not already created
            CLILogs.CreateLoggers();

            string         helpText = PrintHelpErrorUsage(parser);
            ParseException ex       = new ParseException();

            // check if a "help" flag is used
            if (argv.Length > 1 && argv[1] == "help")
            {
                CLILogs.Usage(PrintHelpUsage(parser));
                throw new ParseHelpException();
            }

            if (errs == null)
            {
                CLILogs.Usage(helpText);
                throw ex;
            }

            if (errs.Any(x => x.Tag == CommandLine.ErrorType.VersionRequestedError))
            {
                helpText = PrintHelpVersion(parser);
                ex       = new ParseVersionException();
            }
            else if (errs.Any(x => x.Tag == CommandLine.ErrorType.HelpRequestedError))
            {
                helpText = PrintHelpUsage(parser);
                ex       = new ParseHelpException();
            }
            else if (errs.Any(x => x.Tag == CommandLine.ErrorType.HelpVerbRequestedError))
            {
                helpText = PrintHelpVerbUsage(parser);
                ex       = new ParseHelpException();
            }
            else if (errs.Any(x => x.Tag == CommandLine.ErrorType.NoVerbSelectedError ||
                              x.Tag == CommandLine.ErrorType.BadVerbSelectedError))
            {
                helpText = PrintHelpErrorVerbUsage(parser);
                string errorList = string.Empty;
                errs.ToList().ForEach(e => errorList += e.ToString());
                ex = new ParseException(errorList);
                CLILogs.Debug("Parsing error : " + errorList);
            }
            else
            {
                string errorList = string.Empty;
                errs.ToList().ForEach(e => errorList += e.ToString());
                ex = new ParseException(errorList);
                CLILogs.Debug("Parsing error : " + errorList);
            }

            CLILogs.Usage(helpText);
            throw ex;
        }
Example #3
0
        public void ConfigGetLogOptions(Options.ILogOptions option)
        {
            CLILogs.SetNoColor(option.NoColor);

            CLILogs.CreateLoggers();
        }