protected override CommandBase GetHelpCommand() { if (HelpCommand == null) { HelpCommand = new HelpCommand(_console); HelpCommand.AddLine(string.Format("Help for command {0}. {1}", Name, Description)); HelpCommand.AddLine(HelpText, CanExecute); } return(HelpCommand); }
protected override ICommand GetHelpCommand() { if (HelpCommand == null) { HelpCommand = new HelpCommand(Console); HelpCommand.AddLine(string.Format("Help for command {0}. {1}", Name, Description)); HelpCommand.AddLine(HelpText, CanExecute); } return HelpCommand; }
protected override ICommand GetHelpCommand() { if (HelpCommand == null) { HelpCommand = new HelpCommand(Console); HelpCommand.AddLine(string.Format("Help for command {0}.", Name)); HelpCommand.AddLine(string.Empty); HelpCommand.AddLine(string.Format("Sub Commands for {0}:", Name)); foreach (var command in SubCommands) HelpCommand.AddLine(string.Format("{0} {1}", command.Name.PadString(10), command.Description), command.CanExecute); } return HelpCommand; }
protected override CommandBase GetHelpCommand() { if (HelpCommand == null) { HelpCommand = new HelpCommand(_console); HelpCommand.AddLine(string.Format("Help for command {0}.", Name)); HelpCommand.AddLine(""); HelpCommand.AddLine(string.Format("Sub Commands for {0}:", Name)); foreach (var command in SubCommands) { HelpCommand.AddLine(string.Format("{0} {1}", command.Name.PadString(10), command.Description), command.CanExecute); } } return(HelpCommand); }
protected override ICommand GetHelpCommand(string paramList) { var helpCommand = new HelpCommand(RootCommand.CommandEngine); if (HelpText.Any()) { //TODO: Get the help color //var c = ((SystemConsoleBase)((CommandBase)this).Console).GetConsoleColor(OutputLevel.Title); //var col = ((SystemConsoleBase)Console).GetConsoleColor(OutputLevel.Title); helpCommand.AddLine($"Help for command {Name}.", foreColor: ConsoleColor.DarkCyan); foreach (var helpText in HelpText) { helpCommand.AddLine(helpText.Text, foreColor: helpText.ForeColor); } helpCommand.AddLine(string.Empty); } return(helpCommand); }
protected override ICommand GetHelpCommand(string paramList) { var helpCommand = new HelpCommand(RootCommand.CommandEngine); var showHidden = true; var command = this as ICommand; var subCommand = paramList?.Trim(); if (paramList != " details") { showHidden = false; command = GetSubCommand(paramList, out subCommand); } if (command == null) { helpCommand.AddLine($"There is no command named '{paramList?.Replace(" details", "")}', cannot help with that.", foreColor: ConsoleColor.Yellow); return(helpCommand); } if (command.Name == "root") { var assembly = Assembly.GetEntryAssembly(); helpCommand.AddLine($"Application {assembly?.GetName().Name ?? "main"} help.", foreColor: ConsoleColor.DarkCyan); helpCommand.AddLine($"Version {assembly?.GetName().Version}"); } else { helpCommand.AddLine($"Help for command {command.Name}.", foreColor: ConsoleColor.DarkCyan); helpCommand.AddLine(command.Description); } string reasonMessage; command.CanExecute(out reasonMessage); if (subCommand != null && subCommand.EndsWith("details")) { if (!string.IsNullOrEmpty(reasonMessage)) { helpCommand.AddLine(string.Empty); helpCommand.AddLine("This command can currently not be executed.", foreColor: ConsoleColor.Yellow); helpCommand.AddLine(reasonMessage, foreColor: ConsoleColor.Yellow); } if (command.HelpText.Any()) { foreach (var helpText in command.HelpText) { helpCommand.AddLine(helpText.Text, foreColor: helpText.ForeColor); } } if (command.Name == "root") { helpCommand.AddLine(string.Empty); helpCommand.AddLine("How to use help.", foreColor: ConsoleColor.DarkCyan); helpCommand.AddLine("Use the parameter -? at the end of any command to get more details."); helpCommand.AddLine("It is also possible to type 'help [command]' to get details."); //helpCommand.AddLine(string.Empty); //helpCommand.AddLine("Application parameters.", foreColor: ConsoleColor.DarkCyan); //helpCommand.AddLine(""); //helpCommand.AddLine(string.Empty); //helpCommand.AddLine("More details.", foreColor: ConsoleColor.DarkCyan); //helpCommand.AddLine("Visit https://github.com/poxet/tharga-console."); helpCommand.AddLine(string.Empty); helpCommand.AddLine("Switches:", foreColor: ConsoleColor.DarkCyan); helpCommand.AddLine("/c Keeps the console open when parameters are sent to the console."); helpCommand.AddLine("/e Keeps the console open when parameters are sent to the console and something goes wrong."); helpCommand.AddLine("/r Resets settings."); } } else if (command.HelpText.Any()) { if (command.Name == "root") { helpCommand.AddLine($"Type \"help\" for more information.", foreColor: ConsoleColor.DarkYellow); } else { helpCommand.AddLine($"Type \"{command.Name} -?\" for more information.", foreColor: ConsoleColor.DarkYellow); } } var containerCommand = command as ContainerCommandBase; if (containerCommand != null) { ShowSubCommandHelp(containerCommand._subCommands, helpCommand, reasonMessage, showHidden); } if (command.Names.Count() > 1) { helpCommand.AddLine(string.Empty); helpCommand.AddLine("Alternative names:", foreColor: ConsoleColor.DarkCyan); foreach (var name in command.Names) { helpCommand.AddLine($"{name}"); } } return(helpCommand); }
private void ShowSubCommandHelp(IEnumerable <ICommand> subCommands, HelpCommand helpCommand, string parentReasonMesage, bool showHidden) { var anyHidden = false; var arr = subCommands as ICommand[] ?? subCommands.ToArray(); var actionCommands = arr.Where(x => x is ActionCommandBase).ToArray(); var containerCommands = arr.Where(x => x is ContainerCommandBase).ToArray(); var padLength = containerCommands.Max(x => x.Name.Length, 0).Max(actionCommands.Max(x => x.Name.Length, 0)); if (containerCommands.Any(x => !x.IsHidden || showHidden)) { helpCommand.AddLine(string.Empty); helpCommand.AddLine($"Sections for {Name}:", foreColor: ConsoleColor.DarkCyan); foreach (var command in containerCommands) { if (!command.IsHidden || showHidden) { var hidden = command.IsHidden ? "*" : ""; if (command.IsHidden) { anyHidden = true; } helpCommand.AddLine($"{(hidden + command.Name).PadStringAfter(padLength)} {command.Description}", () => { string reasonMessage; var canExecute = command.CanExecute(out reasonMessage); if (canExecute && !string.IsNullOrEmpty(parentReasonMesage)) { return(false); } return(canExecute); }); } } } if (actionCommands.Any(x => !x.IsHidden || showHidden)) { helpCommand.AddLine(string.Empty); helpCommand.AddLine($"Commands for {Name}:", foreColor: ConsoleColor.DarkCyan); foreach (var command in actionCommands) { if (!command.IsHidden || showHidden) { var hidden = command.IsHidden ? "*" : ""; if (command.IsHidden) { anyHidden = true; } helpCommand.AddLine($"{(hidden + command.Name).PadStringAfter(padLength)} {command.Description}", () => { string reasonMessage; var canExecute = command.CanExecute(out reasonMessage); if (canExecute && !string.IsNullOrEmpty(parentReasonMesage)) { return(false); } return(canExecute); }); } } } if (anyHidden) { helpCommand.AddLine(string.Empty); helpCommand.AddLine($"* = Hidden command"); } }