Esempio n. 1
0
        protected int Run(string[] args, CommandBase command, bool throwOnUnexpectedArg)
        {
            try
            {
                // AllowArgumentSeparator and continueAfterUnexpectedArg are ignored when !throwOnUnexpectedArg _except_
                // AllowArgumentSeparator=true changes the help text (ignoring throwOnUnexpectedArg).
                var app = new CommandLineApplication(throwOnUnexpectedArg, continueAfterUnexpectedArg: true)
                {
                    AllowArgumentSeparator = !throwOnUnexpectedArg,
                    Error    = _console.Error,
                    FullName = Resources.CommandFullName,
                    Name     = Resources.CommandFullName,
                    Out      = _console.Out,
                };

                command.Configure(app);

                return(app.Execute(args));
            }
            catch (Exception ex)
            {
                if (ex is CommandException || ex is CommandParsingException)
                {
                    _reporter.WriteError(ex.Message);
                }
                else
                {
                    _reporter.WriteError(ex.ToString());
                }

                return(1);
            }
        }