Exemplo n.º 1
0
        /// <summary>
        /// Writes the <see cref="Option"/> help content, if any,
        /// for the supplied <see cref="command"/>
        /// </summary>
        /// <param name="command"></param>
        protected virtual void AddOptions(ICommand command)
        {
            var options = command
                          .Children
                          .OfType <IOption>()
                          .Where(ShouldShowHelp)
                          .ToArray();

            HelpSection.Write(this, Options.Title, options, OptionFormatter);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the help content of the <see cref="Command"/> subcommands, if any,
        /// for the supplied <see cref="command"/>
        /// </summary>
        /// <param name="command"></param>
        protected virtual void AddSubcommands(ICommand command)
        {
            var subcommands = command
                              .Children
                              .OfType <ICommand>()
                              .Where(subCommand => subCommand.ShouldShowHelp())
                              .ToArray();

            HelpSection.Write(this, Commands.Title, subcommands, OptionFormatter);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes a summary, if configured, for the supplied <see cref="command"/>
        /// </summary>
        /// <param name="command"></param>
        protected virtual void AddSynopsis(ICommand command)
        {
            if (!ShouldShowHelp(command))
            {
                return;
            }

            var title = $"{command.Name}:";

            HelpSection.Write(this, title, command.Description);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Writes the usage summary for the supplied <see cref="command"/>
        /// </summary>
        /// <param name="command"></param>
        protected virtual void AddUsage(ICommand command)
        {
            var usage = new List <string>();

            var subcommands = command
                              .RecurseWhileNotNull(commandDef => commandDef.Parent)
                              .Reverse();

            foreach (var subcommand in subcommands)
            {
                usage.Add(subcommand.Name);

                if (subcommand != command &&
                    ShouldDisplayArgumentHelp(subcommand, out var subcommandArgName))
                {
                    usage.Add($"<{subcommandArgName}>");
                }
            }

            var hasOptionHelp = command.Children
                                .OfType <IOption>()
                                .Any(symbolDef => symbolDef.ShouldShowHelp());

            if (hasOptionHelp)
            {
                usage.Add(Usage.Options);
            }

            if (ShouldDisplayArgumentHelp(command, out var commandArgName))
            {
                usage.Add($"<{commandArgName}>");
            }

            var hasCommandHelp = command.Children
                                 .OfType <ICommand>()
                                 .Any(f => f.ShouldShowHelp());

            if (hasCommandHelp)
            {
                usage.Add(Usage.Command);
            }

            if (!command.TreatUnmatchedTokensAsErrors)
            {
                usage.Add(Usage.AdditionalArguments);
            }

            HelpSection.Write(this, Usage.Title, string.Join(" ", usage));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Writes the arguments, if any, for the supplied <see cref="command"/>
        /// </summary>
        /// <param name="command"></param>
        protected virtual void AddArguments(ICommand command)
        {
            var commands = new List <ICommand>();

            if (ShouldDisplayArgumentHelp(command.Parent, out var _))
            {
                commands.Add(command.Parent);
            }

            if (ShouldDisplayArgumentHelp(command, out var _))
            {
                commands.Add(command);
            }

            HelpSection.Write(this, Arguments.Title, commands, ArgumentFormatter);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Writes the arguments, if any, for the supplied <see cref="command"/>
        /// </summary>
        /// <param name="command"></param>
        protected virtual void AddArguments(ICommand command)
        {
            var commands = new List <ICommand>();

            if (command is Command cmd &&
                cmd.Parents.FirstOrDefault() is ICommand parent &&
                ShouldDisplayArgumentHelp(parent))
            {
                commands.Add(parent);
            }

            if (ShouldDisplayArgumentHelp(command))
            {
                commands.Add(command);
            }

            HelpSection.Write(this, Arguments.Title, commands, GetArgumentHelpItems);
        }