Exemplo n.º 1
0
        private IDictionary <string, Command> CreateAllCommands()
        {
            var helpCommand        = new HelpCommand();
            var legacyHelpCommand  = new LegacyHelpCommand();
            var allCommandsByArray =
                new Command[]
            {
                helpCommand,
                legacyHelpCommand,
                new VersionCommand(),
                new LegacyVersionCommand(),
                new ChangelogCommand(),
                new LegacyChangelogCommand(),
                new ScanStartCommand(_basicMachines.Scan),
                new LegacyScanStartCommand(_basicMachines.Scan),
                new ScanShowCommand(_basicMachines.Scan),
                new LegacyScanShowCommand(_basicMachines.Scan),
                new ScanEndCommand(_basicMachines.Scan),
                new LegacyScanEndCommand(_basicMachines.Scan),
            };

            helpCommand.HelpMessage       = () => CommandsHelp.Create(allCommandsByArray);
            legacyHelpCommand.HelpMessage = () => CommandsHelp.Create(allCommandsByArray);
            return
                (allCommandsByArray
                 .SelectMany(command => command.GetBodies().Select(body => new { Key = body, Value = command }))
                 .ToDictionary(a => a.Key, a => a.Value));
        }
Exemplo n.º 2
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);
            }
Exemplo n.º 3
0
        public override void WriteCommands(CommandsHelp commands)
        {
            WriteLine(HelpCommand.GetHeadingText());
            WriteLine("Usage: roslynator [command] [arguments]");
            WriteLine();

            if (commands.Commands.Any())
            {
                using (IEnumerator <IGrouping <string, CommandItem> > en = commands.Commands
                                                                           .OrderBy(f => f.Command.Group.Ordinal)
                                                                           .GroupBy(f => f.Command.Group.Name)
                                                                           .GetEnumerator())
                {
                    if (en.MoveNext())
                    {
                        while (true)
                        {
                            WriteHeading((string.IsNullOrEmpty(en.Current.Key)) ? "Commands" : $"{en.Current.Key} commands");

                            int width = commands.Commands.Max(f => f.Command.Name.Length) + 1;

                            foreach (CommandItem command in en.Current)
                            {
                                Write(Options.Indent);
                                WriteTextLine(command.Text);
                            }

                            if (en.MoveNext())
                            {
                                WriteLine();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }

                WriteEndCommands(commands);
            }
            else if (Options.Filter != null)
            {
                WriteLine("No command found");
            }
        }
Exemplo n.º 4
0
        public static void WriteCommandsHelp(bool includeValues = false, Filter?filter = null)
        {
            IEnumerable <Command> commands = LoadCommands();

            CommandsHelp commandsHelp = CommandsHelp.Create(commands, OptionValueProviders.Providers, filter: filter);

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

            writer.WriteCommands(commandsHelp);

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

            WriteLine();
            WriteLine(GetFooterText());
        }