Exemplo n.º 1
0
        private static IConsoleRenderer FormatFullCommandDescription(BaseCommandConfig command, string prefixText = null, IOptionNameHelpAdorner adorner = null, bool displayCommandName = true)
        {
            var formatter = new RecordingConsoleAdapter();
            formatter.WrapLine(((IContext)command).Description ?? string.Empty);

            var positionalsPresent = command.Positionals.Any();
            var optionsPresent = command.Options.Any();
            if (positionalsPresent || optionsPresent)
            {
                formatter.WriteLine();

                var paramList = !positionalsPresent ? String.Empty :
                    " " + command.Positionals.Select(FormatParameterListEntry)
                        .Aggregate((t, i) => t + " " + i);
                var options = !optionsPresent ? String.Empty : " [options]";
                formatter.WrapLine(string.Format("{0}{1}{2}{3}", prefixText ?? String.Empty, displayCommandName ? command.Name : null, paramList, options));
            }

            if (positionalsPresent)
            {
                formatter.WriteLine();
                formatter.WriteLine("Parameters:");
                formatter.WriteLine();
                var positionals = command.Positionals
                    .Select(p => new {p.ParameterName, Description = FormatPositionalDescription(p)});
                formatter.FormatTable(positionals, FormattingOptions, ColumnSeperator);
            }

            if (optionsPresent)
            {
                formatter.WriteLine();
                formatter.WriteLine("Options:");
                formatter.WriteLine();

                var options = command.Options
                    .Select(o => new { OptionName = GetOptionNameAndAliases(adorner, o), o.Description });
                formatter.FormatTable(options, FormattingOptions, ColumnSeperator);
            }

            return formatter;
        }
 private static RecordingConsoleAdapter MakeRecording()
 {
     var recorder = new RecordingConsoleAdapter();
     recorder.Write("Write.");
     recorder.WriteLine("WriteLine.");
     recorder.Wrap("Some wrapped text ");
     recorder.Wrap("added in chunks, followed by ");
     recorder.WrapLine("a final wrap line.");
     var data = Enumerable.Range(1, 10)
                          .Select(i => new { Number = i, String = string.Join(" ", Enumerable.Repeat("blah", i)) });
     recorder.FormatTable(data);
     recorder.Write("<--- END");
     return recorder;
 }