Пример #1
0
        protected virtual int OnExecute(CommandLineApplication app)
        {
            Console.SetWindowTitle("OpenCatapult CLI");

            Console.WriteLine("----------------------------");
            Console.WriteLine("|     OpenCatapult CLI     |");
            Console.WriteLine("----------------------------");
            Console.WriteLine();

            try
            {
                #if DEBUG
                DebugPreprocessing();
#endif

                string resultMessage;

                if (!HelpContext)
                {
                    resultMessage = Execute();
                }
                else if (HelpContextService == null)
                {
                    resultMessage = "Help Context service is not provided";
                }
                else if (string.IsNullOrEmpty(Section))
                {
                    resultMessage = "Help context is not available for this command";
                }
                else
                {
                    var helpContexts = HelpContextService.GetHelpContextsBySection(Section).Result;
                    resultMessage = helpContexts.ToHelpContextString($"Help context for the {Section} commands:");
                }

                if (!string.IsNullOrEmpty(resultMessage))
                {
                    Console.WriteLine(resultMessage);
                }

                Console.WriteLine();

                return(0);
            }
            catch (Exception ex)
            {
                var errorMessage = ex.GetLastInnerExceptionMessage();
                Logger.LogError(ex, errorMessage);

                Console.Error.WriteLine(errorMessage);
                Console.WriteLine();

                return(1);
            }
        }
        public async Task <IActionResult> GetHelpContextsBySection(string section)
        {
            _logger.LogRequest("Getting help contexts for section {section}", section);

            var helpContexts = await _helpContextService.GetHelpContextsBySection(section);

            var results = _mapper.Map <List <HelpContextDto> >(helpContexts);

            _logger.LogResponse("Help contexts for section {section} retrieved. Reponse body: {@results}", section, results);

            return(Ok(results));
        }