/// <summary> /// Search an alias help target. /// </summary> /// <remarks> /// This will, /// a. use _sessionState object to get a list of alias that match the target. /// b. for each alias, retrieve help info as in ExactMatchHelp. /// </remarks> /// <param name="helpRequest">Help request object.</param> /// <param name="searchOnlyContent"> /// If true, searches for pattern in the help content. Individual /// provider can decide which content to search in. /// /// If false, searches for pattern in the command names. /// </param> /// <returns>A IEnumerable of helpinfo object.</returns> internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { // aliases do not have help content...so doing nothing in that case if (!searchOnlyContent) { string target = helpRequest.Target; string pattern = target; Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase); if (!WildcardPattern.ContainsWildcardCharacters(target)) { pattern += "*"; } WildcardPattern matcher = WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase); IDictionary <string, AliasInfo> aliasTable = _sessionState.Internal.GetAliasTable(); foreach (string name in aliasTable.Keys) { if (matcher.IsMatch(name)) { HelpRequest exactMatchHelpRequest = helpRequest.Clone(); exactMatchHelpRequest.Target = name; // Duplicates?? foreach (HelpInfo helpInfo in ExactMatchHelp(exactMatchHelpRequest)) { // Component/Role/Functionality match is done only for SearchHelp // as "get-help * -category alias" should not forwad help to // CommandHelpProvider..(ExactMatchHelp does forward help to // CommandHelpProvider) if (!Match(helpInfo, helpRequest)) { continue; } if (hashtable.ContainsKey(name)) { continue; } hashtable.Add(name, null); yield return(helpInfo); } } } CommandSearcher searcher = new CommandSearcher( pattern, SearchResolutionOptions.ResolveAliasPatterns, CommandTypes.Alias, _context); while (searcher.MoveNext()) { CommandInfo current = ((IEnumerator <CommandInfo>)searcher).Current; if (_context.CurrentPipelineStopping) { yield break; } AliasInfo alias = current as AliasInfo; if (alias != null) { string name = alias.Name; HelpRequest exactMatchHelpRequest = helpRequest.Clone(); exactMatchHelpRequest.Target = name; // Duplicates?? foreach (HelpInfo helpInfo in ExactMatchHelp(exactMatchHelpRequest)) { // Component/Role/Functionality match is done only for SearchHelp // as "get-help * -category alias" should not forwad help to // CommandHelpProvider..(ExactMatchHelp does forward help to // CommandHelpProvider) if (!Match(helpInfo, helpRequest)) { continue; } if (hashtable.ContainsKey(name)) { continue; } hashtable.Add(name, null); yield return(helpInfo); } } } foreach (CommandInfo current in ModuleUtils.GetMatchingCommands(pattern, _context, helpRequest.CommandOrigin)) { if (_context.CurrentPipelineStopping) { yield break; } AliasInfo alias = current as AliasInfo; if (alias != null) { string name = alias.Name; HelpInfo helpInfo = AliasHelpInfo.GetHelpInfo(alias); if (hashtable.ContainsKey(name)) { continue; } hashtable.Add(name, null); yield return(helpInfo); } } } }
private void AccumulateMatchingCommands(IEnumerable <string> commandNames) { SearchResolutionOptions none = SearchResolutionOptions.None; if (this.All != false) { none = SearchResolutionOptions.SearchAllScopes; } if ((this.CommandType & CommandTypes.Alias) != 0) { none |= SearchResolutionOptions.ResolveAliasPatterns; } if ((this.CommandType & (CommandTypes.Workflow | CommandTypes.Filter | CommandTypes.Function)) != 0) { none |= SearchResolutionOptions.ResolveFunctionPatterns; } foreach (string str in commandNames) { try { string str2 = null; string pattern = str; bool flag = false; if ((str.IndexOf('\\') > 0) && (str.Split(new char[] { '\\' }).Length == 2)) { string[] strArray = str.Split(new char[] { '\\' }, 2); str2 = strArray[0]; pattern = strArray[1]; flag = true; } if ((this.Module.Length == 1) && !WildcardPattern.ContainsWildcardCharacters(this.Module[0])) { str2 = this.Module[0]; } bool isPattern = WildcardPattern.ContainsWildcardCharacters(pattern); if (isPattern) { none |= SearchResolutionOptions.CommandNameIsPattern; } int currentCount = 0; bool flag3 = this.FindCommandForName(none, str, isPattern, true, ref currentCount); if (!flag3 || isPattern) { if (!isPattern || !string.IsNullOrEmpty(str2)) { string commandName = str; if (!flag && !string.IsNullOrEmpty(str2)) { commandName = str2 + @"\" + str; } try { CommandDiscovery.LookupCommandInfo(commandName, base.MyInvocation.CommandOrigin, base.Context); } catch (CommandNotFoundException) { } flag3 = this.FindCommandForName(none, str, isPattern, false, ref currentCount); } else if ((this.ListImported == false) && ((this.TotalCount < 0) || (currentCount < this.TotalCount))) { foreach (CommandInfo info in ModuleUtils.GetMatchingCommands(pattern, base.Context, base.MyInvocation.CommandOrigin, true)) { CommandInfo current = info; if ((this.IsCommandMatch(ref current) && !this.IsCommandInResult(current)) && this.IsParameterMatch(current)) { this.accumulatedResults.Add(current); currentCount++; if ((this.TotalCount >= 0) && (currentCount >= this.TotalCount)) { break; } } } } } if (!flag3 && !isPattern) { CommandNotFoundException replaceParentContainsErrorRecordException = new CommandNotFoundException(str, null, "CommandNotFoundException", DiscoveryExceptions.CommandNotFoundException, new object[0]); base.WriteError(new ErrorRecord(replaceParentContainsErrorRecordException.ErrorRecord, replaceParentContainsErrorRecordException)); } } catch (CommandNotFoundException exception2) { base.WriteError(new ErrorRecord(exception2.ErrorRecord, exception2)); } } }
internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { string item = helpRequest.Target; Collection <string> iteratorVariable1 = new Collection <string>(); WildcardPattern pattern = null; bool iteratorVariable3 = !WildcardPattern.ContainsWildcardCharacters(helpRequest.Target); if (!searchOnlyContent) { if (iteratorVariable3) { if (item.IndexOf('-') >= 0) { iteratorVariable1.Add(item + "*"); } else { iteratorVariable1.Add("*" + item + "*"); } } else { iteratorVariable1.Add(item); } } else { iteratorVariable1.Add("*"); string target = helpRequest.Target; if (iteratorVariable3) { target = "*" + helpRequest.Target + "*"; } pattern = new WildcardPattern(target, WildcardOptions.IgnoreCase | WildcardOptions.Compiled); } int iteratorVariable4 = 0; Hashtable iteratorVariable5 = new Hashtable(StringComparer.OrdinalIgnoreCase); Hashtable iteratorVariable6 = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (string iteratorVariable7 in iteratorVariable1) { CommandSearcher commandSearcherForSearch = this.GetCommandSearcherForSearch(iteratorVariable7, this._context); while (commandSearcherForSearch.MoveNext()) { if (this._context.CurrentPipelineStopping) { break; } CommandInfo current = commandSearcherForSearch.Current; CmdletInfo cmdletInfo = current as CmdletInfo; HelpInfo helpInfo = null; string key = null; if (cmdletInfo != null) { helpInfo = this.GetHelpInfo(cmdletInfo, !iteratorVariable3); key = cmdletInfo.FullName; } else { IScriptCommandInfo scriptCommandInfo = current as IScriptCommandInfo; if (scriptCommandInfo != null) { key = current.Name; helpInfo = this.GetHelpInfo(scriptCommandInfo, !iteratorVariable3, searchOnlyContent); } } if (helpInfo != null) { if (!SessionState.IsVisible(helpRequest.CommandOrigin, current)) { if (!iteratorVariable6.ContainsKey(key)) { iteratorVariable6.Add(key, null); } } else if ((!iteratorVariable5.ContainsKey(key) && Match(helpInfo, helpRequest, current)) && (!searchOnlyContent || helpInfo.MatchPatternInContent(pattern))) { iteratorVariable5.Add(key, null); iteratorVariable4++; yield return(helpInfo); if ((iteratorVariable4 < helpRequest.MaxResults) || (helpRequest.MaxResults <= 0)) { continue; } break; } } } if (this.HelpCategory == (System.Management.Automation.HelpCategory.Cmdlet | System.Management.Automation.HelpCategory.Alias)) { foreach (CommandInfo iteratorVariable13 in ModuleUtils.GetMatchingCommands(iteratorVariable7, this._context, helpRequest.CommandOrigin, false)) { if (this._context.CurrentPipelineStopping) { break; } if (SessionState.IsVisible(helpRequest.CommandOrigin, iteratorVariable13)) { CmdletInfo iteratorVariable14 = iteratorVariable13 as CmdletInfo; HelpInfo iteratorVariable15 = null; string fullName = null; if (iteratorVariable14 != null) { iteratorVariable15 = this.GetHelpInfo(iteratorVariable14, !iteratorVariable3); fullName = iteratorVariable14.FullName; } else { IScriptCommandInfo info2 = iteratorVariable13 as IScriptCommandInfo; if (info2 != null) { fullName = iteratorVariable13.Name; iteratorVariable15 = this.GetHelpInfo(info2, !iteratorVariable3, searchOnlyContent); } } if ((((iteratorVariable15 != null) && !iteratorVariable5.ContainsKey(fullName)) && (!iteratorVariable6.ContainsKey(fullName) && Match(iteratorVariable15, helpRequest, iteratorVariable13))) && (!searchOnlyContent || iteratorVariable15.MatchPatternInContent(pattern))) { iteratorVariable5.Add(fullName, null); iteratorVariable4++; yield return(iteratorVariable15); if ((iteratorVariable4 >= helpRequest.MaxResults) && (helpRequest.MaxResults > 0)) { break; } } } } } } }
internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { if (!searchOnlyContent) { string target = helpRequest.Target; string pattern = target; Hashtable iteratorVariable2 = new Hashtable(StringComparer.OrdinalIgnoreCase); if (!WildcardPattern.ContainsWildcardCharacters(target)) { pattern = pattern + "*"; } WildcardPattern iteratorVariable3 = new WildcardPattern(pattern, WildcardOptions.IgnoreCase); IDictionary <string, AliasInfo> aliasTable = this._sessionState.Internal.GetAliasTable(); foreach (string iteratorVariable5 in aliasTable.Keys) { if (iteratorVariable3.IsMatch(iteratorVariable5)) { HelpRequest iteratorVariable6 = helpRequest.Clone(); iteratorVariable6.Target = iteratorVariable5; foreach (HelpInfo iteratorVariable7 in this.ExactMatchHelp(iteratorVariable6)) { if (!Match(iteratorVariable7, helpRequest) || iteratorVariable2.ContainsKey(iteratorVariable5)) { continue; } iteratorVariable2.Add(iteratorVariable5, null); yield return(iteratorVariable7); } } } CommandSearcher iteratorVariable8 = new CommandSearcher(pattern, SearchResolutionOptions.ResolveAliasPatterns, CommandTypes.Alias, this._context); while (iteratorVariable8.MoveNext()) { CommandInfo current = iteratorVariable8.Current; if (this._context.CurrentPipelineStopping) { goto Label_0423; } AliasInfo iteratorVariable10 = current as AliasInfo; if (iteratorVariable10 != null) { string name = iteratorVariable10.Name; HelpRequest iteratorVariable12 = helpRequest.Clone(); iteratorVariable12.Target = name; foreach (HelpInfo iteratorVariable13 in this.ExactMatchHelp(iteratorVariable12)) { if (!Match(iteratorVariable13, helpRequest) || iteratorVariable2.ContainsKey(name)) { continue; } iteratorVariable2.Add(name, null); yield return(iteratorVariable13); } } } foreach (CommandInfo iteratorVariable14 in ModuleUtils.GetMatchingCommands(pattern, this._context, helpRequest.CommandOrigin, false)) { if (this._context.CurrentPipelineStopping) { break; } AliasInfo aliasInfo = iteratorVariable14 as AliasInfo; if (aliasInfo != null) { string key = aliasInfo.Name; HelpInfo helpInfo = AliasHelpInfo.GetHelpInfo(aliasInfo); if (!iteratorVariable2.ContainsKey(key)) { iteratorVariable2.Add(key, null); yield return(helpInfo); } } } } Label_0423: yield break; }