Esempio n. 1
0
        public static void WriteCommandHelp(Command command, bool includeValues = false, Filter filter = null)
        {
            var writer = new ConsoleHelpWriter(new HelpWriterOptions(filter: filter));

            command = command.WithOptions(command.Options.Sort(CommandOptionComparer.Name));

            CommandHelp commandHelp = CommandHelp.Create(command, providers: null, filter: filter);

            writer.WriteCommand(commandHelp);

            if (includeValues)
            {
                writer.WriteValues(commandHelp.Values);
            }
        }
Esempio n. 2
0
        public static void WriteCommandsHelp(bool includeValues = false, Filter filter = null)
        {
            IEnumerable <Command> commands = LoadCommands().Where(f => f.Name != "help");

            CommandsHelp commandsHelp = CommandsHelp.Create(commands, providers: null, filter: filter);

            var writer = new ConsoleHelpWriter(new HelpWriterOptions(filter: filter));

            writer.WriteCommands(commandsHelp);

            if (includeValues)
            {
                writer.WriteValues(commandsHelp.Values);
            }

            WriteLine();
            WriteLine(GetFooterText());
        }
Esempio n. 3
0
        private static void WriteManual(bool includeValues = false, Filter filter = null)
        {
            IEnumerable <Command> commands = LoadCommands();

            var writer = new ConsoleHelpWriter(new HelpWriterOptions(filter: filter));

            IEnumerable <CommandHelp> commandHelps = commands.Select(f => CommandHelp.Create(f, filter: filter))
                                                     .Where(f => f.Arguments.Any() || f.Options.Any())
                                                     .ToImmutableArray();

            ImmutableArray <CommandItem> commandItems = HelpProvider.GetCommandItems(commandHelps.Select(f => f.Command));

            ImmutableArray <OptionValueList> values = ImmutableArray <OptionValueList> .Empty;

            if (commandItems.Any())
            {
                values = HelpProvider.GetOptionValues(
                    commandHelps.SelectMany(f => f.Command.Options),
                    providers: ImmutableArray <OptionValueProvider> .Empty,
                    filter);

                var commandsHelp = new CommandsHelp(commandItems, values);

                writer.WriteCommands(commandsHelp);

                foreach (CommandHelp commandHelp in commandHelps)
                {
                    WriteSeparator();
                    WriteLine();
                    WriteLine($"Command: {commandHelp.Name}");
                    WriteLine();

                    string description = commandHelp.Description;

                    if (!string.IsNullOrEmpty(description))
                    {
                        WriteLine(description);
                        WriteLine();
                    }

                    writer.WriteCommand(commandHelp);
                }

                if (includeValues)
                {
                    WriteSeparator();
                }
            }
            else
            {
                WriteLine();
                WriteLine("No command found");

                if (includeValues)
                {
                    values = HelpProvider.GetOptionValues(
                        commands.Select(f => CommandHelp.Create(f)).SelectMany(f => f.Command.Options),
                        providers: ImmutableArray <OptionValueProvider> .Empty,
                        filter);
                }
            }

            if (includeValues)
            {
                writer.WriteValues(values);
            }