protected override void OnExecute() { if (this.CommandNames.Length == 0) { this.PrintList(); } else { var argList = new List <string>(this.CommandNames); var command = CommandContextBase.GetCommand(this.CommandContext.Node, argList); if (command != null && argList.Any() == false) { if (command is ICommandUsage usage) { usage.Print(this.Usage); } else { throw new InvalidOperationException(Resources.Exception_NotProvideHelp); } } else { var commandName = CommandStringUtility.Join(this.CommandNames); throw new InvalidOperationException(string.Format(Resources.Exception_CommandDoesNotExists_Format, commandName)); } } }
public static void PrintBaseUsage(CommandContextBase commandContext) { var helpCommand = commandContext.HelpCommand; var versionCommand = commandContext.VersionCommand; var helpName = helpCommand.Name; var name = commandContext.ExecutionName; var versionName = versionCommand.Name; var isNameVisible = commandContext.IsNameVisible; using var writer = new StringWriter(); if (helpCommand is ICommandUsage helpUsage) { helpUsage.Print(CommandUsage.None); } if (versionCommand is ICommandUsage versionUsage) { versionUsage.Print(CommandUsage.None); } if (isNameVisible == true) { writer.WriteLine(Resources.Message_HelpUsage_Format, name, helpName); writer.WriteLine(Resources.Message_VersionUsage_Format, name, versionName); } else { writer.WriteLine(Resources.Message_Help_Format, helpName); writer.WriteLine(Resources.Message_Version_Format, versionName); } writer.WriteLine(); commandContext.Out.Write(writer.ToString()); }
public CommandContextTerminal(CommandContextBase commandContext) { this.commandContext = commandContext; }
public CommandNode(CommandContextBase commandContext) { this.CommandContext = commandContext; }