public override int Invoke(IEnumerable <string> arguments) { List <string> extra = arguments.ToList(); Console.WriteLine($"# Help requested for: {string.Join(" ", extra)}"); MessageLocalizerConverter _ = CommandSet.Options.MessageLocalizer; if (extra.Count == 0) { CommandSet.Options.WriteOptionDescriptions(CommandSet.Out); return(0); } Command command = CommandSet.GetCommand(extra); if (command == this || extra.Contains("--help")) { CommandSet.Out.WriteLine(_($"Usage: {CommandSet.Suite} COMMAND [OPTIONS]")); CommandSet.Out.WriteLine(_($"Use `{CommandSet.Suite} help COMMAND` for help on a specific command.")); CommandSet.Out.WriteLine(); CommandSet.Out.WriteLine(_("Available commands:")); CommandSet.Out.WriteLine(); List <KeyValuePair <string, Command> > commands = getCommands(); commands.Sort((x, y) => string.Compare(x.Key, y.Key, StringComparison.OrdinalIgnoreCase)); foreach (KeyValuePair <string, Command> c in commands) { if (c.Key == "help") { continue; } CommandSet.Options.WriteCommandDescription(CommandSet.Out, c.Value, c.Key); } CommandSet.Options.WriteCommandDescription(CommandSet.Out, CommandSet.help, "help"); return(0); } if (command == null) { WriteUnknownCommand(extra[0]); return(1); } if (command.Options != null) { command.Options.WriteOptionDescriptions(CommandSet.Out); return(0); } return(command.Invoke(new[] { "--help" })); }
private bool alreadyAdded(CommandSet commandSet) { if (commandSet == this) { return(true); } if (NestedCommandSets == null) { return(false); } foreach (CommandSet nc in NestedCommandSets) { if (nc.alreadyAdded(commandSet)) { return(true); } } return(false); }
private static void addNestedCommands(ICollection <KeyValuePair <string, Command> > commands, string outer, CommandSet value) { foreach (Command v in value) { commands.Add(new KeyValuePair <string, Command>($"{outer}{value.Suite} {v.Name}", v)); } if (value.NestedCommandSets == null) { return; } foreach (CommandSet nc in value.NestedCommandSets) { addNestedCommands(commands, $"{outer}{value.Suite} ", nc); } }
public CommandOptionSet(CommandSet commands, Converter <string, string> localizer) : base(localizer) { this.commands = commands; }