コード例 #1
0
ファイル: Option.cs プロジェクト: skreddy6673/cafe
        public Result Run(params Argument[] args)
        {
            Result result      = null;
            var    description = ToDescription(args);

            try
            {
                if (_showHelpContext)
                {
                    Presenter.NewLine();
                    Presenter.ShowMessage($"{description}:", Logger);
                    Presenter.NewLine();
                }
                result = RunCore(args);
            }
            catch (AggregateException ae)
            {
                var inner = ae.InnerExceptions.FirstOrDefault(e => e is HttpRequestException);
                if (inner != null)
                {
                    result = BadConnectionFailureFromException(ae);
                }
                else
                {
                    result = GenericFailureFromException(ae);
                }
            }
            catch (HttpRequestException re)
            {
                result = BadConnectionFailureFromException(re);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "An unexpected error occurred while executing this option");
                result = GenericFailureFromException(ex);
            }
            finally
            {
                if (_showHelpContext)
                {
                    Presenter.NewLine();
                    Presenter.ShowMessage($"Finished {description} with result: {result}", Logger);
                }
            }
            return(result);
        }
コード例 #2
0
        public void ShowHelp()
        {
            if (_groupSpecification.ValueSpecifications.Length > 0 && _groupSpecification.ToString().Length > 0)
            {
                Presenter.ShowMessage($"-- {_groupSpecification} --", Logger);
            }
            if (_childGroups.Count > 0)
            {
                foreach (var childGroup in _childGroups)
                {
                    childGroup.ShowHelp();
                    Presenter.NewLine();
                }

                Presenter.NewLine();
                Presenter.ShowMessage("-- other options --", Logger);
            }

            foreach (var optionPair in _childOptions)
            {
                var help = new HelpOption(this, optionPair.Value, optionPair.Key);
                help.Run();
            }
        }