public void WriteHelpItem(ICommandRoot helpItem, int indent = 0) { ConsoleHelper.WriteWithIndent(helpItem.Name, indent * IndentAmount, ColorH1); Console.WriteLine(); ConsoleHelper.WriteWithIndent(new String(HeaderSeparatorChar, helpItem.Name.Length), indent * IndentAmount, Color.Gray); Console.WriteLine(); ConsoleHelper.WriteWithIndent(helpItem.Description, indent * IndentAmount); Console.WriteLine(); Console.WriteLine(); ConsoleHelper.WriteWithIndent("Usage:", indent * IndentAmount, ColorH1); Console.WriteLine(); string rootVerbs = string.Join(" ", helpItem.CommonTokens.Select(x => x.Name.Preferred)); foreach (ICommandUsage usage in helpItem.Usages) { if (usage.IsHelp) { continue; } WriteHelpItem(helpItem, usage, indent + 1); } }
public void WriteHelpItem(ICommandRoot root, ICommandUsage helpItem, int indent = 0) { string rootVerbs = string.Join(" ", root.CommonTokens.Select(x => x.Name.Preferred)); string usageArgs = string.Join(" ", helpItem.Tokens.Select(x => GetOptionalDisplayName(x))); ConsoleHelper.WriteWithIndent($"{rootVerbs} {usageArgs}", indent * IndentAmount); Console.WriteLine(); Console.WriteLine(); ConsoleHelper.WriteWithIndent("Options:", (indent - 1) * IndentAmount, ColorH1); Console.WriteLine(); Console.WriteLine(); int descriptionIndent = indent * IndentAmount + helpItem.Tokens.Max(x => x.DisplayName.Length); foreach (var token in helpItem.Tokens) { if (token.IsOptional) { ConsoleHelper.WriteWithIndent($"{token.DisplayName}", indent * IndentAmount); ConsoleHelper.WriteWithIndent(" # ", descriptionIndent, Color.Gray); ConsoleHelper.WriteWithIndent(helpItem.GetDescription(token), descriptionIndent + 4, Color.Gray); object defaultValue = helpItem.GetDefaultValue(token); if (defaultValue != null) { ConsoleHelper.WriteWithIndent($" [default: {defaultValue.ToString()}]", descriptionIndent + 4, Color.Gray); } if (token.PossibleValues != null && token.PossibleValues.Length > 0) { Console.WriteLine(); ConsoleHelper.WriteWithIndent($"Possible Values: {{{string.Join(", ", token.PossibleValues)}}}", descriptionIndent + 8); } Console.WriteLine(); } } Console.WriteLine(); ConsoleHelper.WriteWithIndent("Examples:", (indent - 1) * IndentAmount, ColorH1); Console.WriteLine(); Console.WriteLine(); foreach (var example in helpItem.Examples) { ConsoleHelper.WriteWithIndent(example, indent * IndentAmount); Console.WriteLine(); } }
public bool TryGetCommand(string text, out ICommandRoot command) { float bestMatchQuality = 0; command = null; foreach (var c in _commands) { TokenMatchCollection match = CommandParser.Match(c.CommonTokens, text); if (match.MatchQuality > bestMatchQuality) { bestMatchQuality = match.MatchQuality; command = c; } } return(bestMatchQuality > 0); }
public CommandUsageMatchData(ICommandRoot command, ICommandUsage usage, TokenMatchCollection matchCollection) { Command = command; Usage = usage; _matchCollection = matchCollection; }
public CommandLibrary AddCommand(ICommandRoot command) { _commands.Add(command); return(this); }
private bool HasHelpOption(ICommandRoot commandRoot) { return(commandRoot.Usages.Any(x => x.Tokens.Contains(BudgetCliCommands.OPT_HELP_REQUIRED))); }
public HelpCommand(string rawText, RepositoryBag repositories, ICommandRoot helpTarget) : base(rawText, repositories) { HelpTarget = helpTarget; }
public CommandRootUsage(ICommandRoot root) { CommandRoot = root; }
public static Dictionary <ICommandUsage, TokenMatchCollection> GetUsageMatchResults(ICommandRoot currentRoot, string text) { Dictionary <ICommandUsage, TokenMatchCollection> usageMatchData = new Dictionary <ICommandUsage, TokenMatchCollection>(); if (currentRoot.Usages.Any()) { foreach (var usage in currentRoot.Usages) { ICommandToken[] tokens = currentRoot.CommonTokens.Concat(usage.Tokens).ToArray(); TokenMatchCollection matchCollection = Match(tokens, text); usageMatchData.Add(usage, matchCollection); } } else { ICommandToken[] tokens = currentRoot.CommonTokens.ToArray(); TokenMatchCollection matchCollection = Match(tokens, text); usageMatchData.Add(new CommandRootUsage(currentRoot), matchCollection); } return(usageMatchData); }
public HelpCommandResult(ICommandAction command, bool isSuccessful, ICommandRoot target) { CommandAction = command; IsSuccessful = isSuccessful; CommandRootTarget = target; }