コード例 #1
0
        public void WriteCommandHelp(ICommandLineOutput output, CommandModel command)
        {
            string commandName = _commandFormatter.FormatCommandName(command.Name);

            output.WriteLine(Colors.White, "NAME:");
            output.Write(' ', NestedLineOffset);
            output.WriteLine(Colors.Yellow, commandName);
            output.WriteLine();

            if (!String.IsNullOrWhiteSpace(command.Description))
            {
                output.WriteLine(Colors.White, "DESCRIPTION:");
                output.Write(' ', NestedLineOffset);
                output.WriteLine(Colors.DarkGray, command.Description);
                output.WriteLine();
            }

            string syntax = _commandFormatter.FormatCommand(command);

            output.WriteLine(Colors.White, "SYNTAX:");
            output.Write(' ', NestedLineOffset);
            output.WriteLine(syntax);
            output.WriteLine();

            var options = command.Arguments
                          .Where(_ => _.Kind == ArgumentKind.Option)
                          .OrderBy(_ => _.Name)
                          .ToArray();

            var operands = command.Arguments
                           .Where(_ => _.Kind == ArgumentKind.Operand)
                           .ToArray();

            int maxOptionNameLength  = GetMax(options, GetOptionNameLength, MaxNameLength);
            int maxOperandNameLength = GetMax(operands, _ => _.Name.Length, MaxNameLength);
            int maxArgNameLength     = Math.Max(maxOptionNameLength, maxOperandNameLength);

            if (options.Length > 0)
            {
                PrintOptionsList(output, options, maxArgNameLength);
                output.WriteLine();
            }

            if (operands.Length > 0)
            {
                PrintOperandsList(output, operands, maxArgNameLength);
                output.WriteLine();
            }
        }