Beispiel #1
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.GetAllowedValues(commandHelps.SelectMany(f => f.Command.Options), OptionValueProviders.Providers, 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.GetAllowedValues(commands.Select(f => CommandHelp.Create(f)).SelectMany(f => f.Command.Options), OptionValueProviders.Providers, filter);
                }
            }

            if (includeValues)
            {
                writer.WriteValues(values);
            }
Beispiel #2
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(CompareOptions));

            CommandHelp commandHelp = CommandHelp.Create(command, OptionValueProviders.Providers, filter: filter);

            writer.WriteCommand(commandHelp);

            if (includeValues)
            {
                writer.WriteValues(commandHelp.Values);
            }
            else
            {
                IEnumerable <string> metaValues = OptionValueProviders.GetProviders(commandHelp.Options.Select(f => f.Option), OptionValueProviders.Providers).Select(f => f.Name);

                if (metaValues.Any())
                {
                    WriteLine();
                    Write($"Run 'orang help {command.Name} -v d' to display list of allowed values for ");
                    Write(TextHelpers.Join(", ", " and ", metaValues));
                    WriteLine(".");
                }
            }
        }
Beispiel #3
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);
            }
        }