Beispiel #1
0
        private void PrintCommandsList(ICommandLineOutput output, IReadOnlyList <CommandModel> commands)
        {
            var commandsInfo = commands.Select(c => new
            {
                Name    = _commandFormatter.FormatCommandName(c.Name),
                Command = c
            })
                               .OrderBy(_ => _.Name)
                               .ToArray();

            int maxNameLength = GetMax(commandsInfo, _ => _.Name.Length, MaxNameLength);

            output.WriteLine(Colors.White, "COMMANDS:");

            foreach (var cmdInfo in commandsInfo)
            {
                output.Write(' ', NestedLineOffset);
                output.Write(Colors.Yellow, cmdInfo.Name);

                if (!String.IsNullOrWhiteSpace(cmdInfo.Command.Description))
                {
                    int descrOffset = GetPadding(cmdInfo.Name.Length, maxNameLength) + DescriptionOffset;
                    output.Write(' ', descrOffset);
                    output.Write(Colors.DarkGray, cmdInfo.Command.Description);
                }

                output.WriteLine();
            }
        }
Beispiel #2
0
        private void PrintOptionsList(ICommandLineOutput output, ArgumentModel[] options, int nameSpace)
        {
            output.WriteLine(Colors.White, "OPTIONS:");

            foreach (var opt in options)
            {
                output.Write(' ', NestedLineOffset);
                int nameLength = 0;

                if (!String.IsNullOrWhiteSpace(opt.Alias))
                {
                    output.Write(Colors.DarkGreen, '-');
                    output.Write(Colors.DarkGreen, opt.Alias);
                    output.Write(Colors.DarkGreen, OptionNameAliasSeparator);
                    nameLength += 1 + opt.Alias.Length + OptionNameAliasSeparator.Length;
                }

                output.Write(Colors.DarkGreen, "--");
                output.Write(Colors.DarkGreen, opt.Name);
                nameLength += 2 + opt.Name.Length;

                if (!String.IsNullOrWhiteSpace(opt.Description))
                {
                    int descrOffset = GetPadding(nameLength, nameSpace) + DescriptionOffset;
                    output.Write(' ', descrOffset);
                    output.Write(Colors.DarkGray, opt.Description);
                }

                output.WriteLine();
            }
        }
Beispiel #3
0
 private void PrintUsage(ICommandLineOutput output)
 {
     output.WriteLine(Colors.White, "USAGE:");
     output.Write(' ', NestedLineOffset);
     output.WriteLine(new ColoredFormat("{0} [{1}] [{2}]")
     {
         { "command name", Colors.Yellow },
         { "options...", Colors.DarkGreen },
         { "operands...", Colors.DarkCyan }
     });
 }
Beispiel #4
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();
            }
        }
Beispiel #5
0
        public void WriteGeneralHelp(ICommandLineOutput output, IReadOnlyList <CommandModel> commands)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }
            if (commands == null)
            {
                throw new ArgumentNullException(nameof(commands));
            }

            PrintUsage(output);
            output.WriteLine();

            if (commands.Count != 0)
            {
                PrintCommandsList(output, commands);
                output.WriteLine();
            }
        }
Beispiel #6
0
        private void PrintOperandsList(ICommandLineOutput output, ArgumentModel[] operands, int nameSpace)
        {
            output.WriteLine(Colors.White, "OPERANDS:");

            foreach (var opr in operands)
            {
                output.Write(' ', NestedLineOffset);
                int nameLength = opr.Name.Length;

                output.Write(Colors.DarkCyan, opr.Name);

                if (!String.IsNullOrWhiteSpace(opr.Description))
                {
                    int descrOffset = GetPadding(nameLength, nameSpace) + DescriptionOffset;
                    output.Write(' ', descrOffset);
                    output.Write(Colors.DarkGray, opr.Description);
                }

                output.WriteLine();
            }
        }
Beispiel #7
0
 public void Clear(ICommandLineOutput output)
 {
     output.Clear();
 }