private Command tryGetNestedCommand(List <string> extra) { CommandSet nestedCommands = NestedCommandSets?.Find(c => c.Suite == extra[0]); if (nestedCommands == null) { return(null); } List <string> extraCopy = new List <string>(extra); extraCopy.RemoveAt(0); if (extraCopy.Count == 0) { return(null); } Command command = nestedCommands.GetCommand(extraCopy); if (command != null) { extra.Clear(); extra.AddRange(extraCopy); return(command); } return(null); }
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" })); }