Пример #1
0
        protected virtual void RenderParameterList(ICommandLineReader <IHelpParameter> parameter)
        {
            var commandId   = new Identifier(parameter.GetItem(x => x.Command));
            var commandType = _commandTypes.SingleOrDefault(t => CommandHelper.GetCommandId(t) == commandId);

            if (commandType is null)
            {
                throw DynamicException.Create
                      (
                          $"CommandNotFound",
                          $"Could not find a command with the name '{parameter.GetItem(x => x.Command)}'"
                      );
            }

            // Headers
            var captions = new[] { "NAME", "ABOUT" }.Pad(ColumnWidths);

            Logger.WriteLine(p => p.text(string.Join(string.Empty, captions)));

            // Separators
            var separators = captions.Select(c => new string('-', c.Trim().Length)).Pad(ColumnWidths);

            Logger.WriteLine(p => p.text(string.Join(string.Empty, separators)));

            var bagType    = commandType.GetBagType();
            var parameters =
                from commandParameter in bagType.GetParameters()
                orderby commandParameter.Id.Default.ToString()
                select commandParameter;

            foreach (var commandParameter in parameters)
            {
                var defaultId = commandParameter.Id.Default.ToString();
                var aliases = string.Join("|", commandParameter.Id.Aliases.Select(x => x.ToString()));
                var description = commandParameter.Description ?? "N/A";
                var row = new[] { $"{defaultId} ({(aliases.Length > 0 ? aliases : "-")})", description }.Pad(ColumnWidths);
                Logger.WriteLine(p => p.text(string.Join(string.Empty, row)));
            }
        }
Пример #2
0
        protected override Task ExecuteAsync(ICommandLineReader <IHelpParameter> parameter, NullContext context, CancellationToken cancellationToken)
        {
            var commandSelected = parameter.GetItem(x => x.Command).IsNotNullOrEmpty();

            if (commandSelected)
            {
                RenderParameterList(parameter);
            }
            else
            {
                RenderCommandList(parameter);
            }

            return(Task.CompletedTask);
        }