internal static List <CompletionResult> PSv2GenerateMatchSetOfCmdlets(CompletionExecutionHelper helper, string lastWord, string quote, bool completingAtStartOfLine) { bool flag; List <CompletionResult> results = new List <CompletionResult>(); if (PSv2IsCommandLikeCmdlet(lastWord, out flag)) { Exception exception; helper.CurrentPowerShell.AddCommand("Get-Command").AddParameter("Name", lastWord + "*").AddCommand("Sort-Object").AddParameter("Property", "Name"); Collection <PSObject> collection = helper.ExecuteCurrentPowerShell(out exception, null); if ((collection == null) || (collection.Count <= 0)) { return(results); } CommandAndName[] cmdlets = new CommandAndName[collection.Count]; for (int i = 0; i < collection.Count; i++) { PSObject psObject = collection[i]; string fullName = CmdletInfo.GetFullName(psObject); cmdlets[i] = new CommandAndName(psObject, PSSnapinQualifiedName.GetInstance(fullName)); } if (flag) { foreach (CommandAndName name in cmdlets) { AddCommandResult(name, true, completingAtStartOfLine, quote, results); } return(results); } PrependSnapInNameForSameCmdletNames(cmdlets, completingAtStartOfLine, quote, results); } return(results); }
private string[] GenerateMatchSetOfCmdlets( string lastWord, bool isPSSnapInSpecified, CultureInfo ci) { using (CommandCompletionBase.tracer.TraceMethod(lastWord, new object[0])) { string[] strArray = (string[])null; Collection <PSObject> collection = this.exec.ExecuteCommand(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "& {{ trap {{ continue }} ; get-command '{0}' -type Cmdlet }}", (object)(lastWord + "*"))); if (collection != null && collection.Count > 0) { PSSnapinQualifiedName[] snapinQualifiedNameArray = new PSSnapinQualifiedName[collection.Count]; for (int index = 0; index < collection.Count; ++index) { string fullName = CmdletInfo.GetFullName(collection[index]); snapinQualifiedNameArray[index] = PSSnapinQualifiedName.GetInstance(fullName); } Array.Sort <PSSnapinQualifiedName>(snapinQualifiedNameArray, new Comparison <PSSnapinQualifiedName>(CommandCompletionBase.PSSnapinQualifiedNameComparison)); if (isPSSnapInSpecified) { strArray = new string[collection.Count]; for (int index = 0; index < snapinQualifiedNameArray.Length; ++index) { strArray[index] = snapinQualifiedNameArray[index].FullName; } } else { strArray = CommandCompletionBase.PrependPSSnapInNameForSameCmdletNames(snapinQualifiedNameArray); } } return(strArray); } }
internal static string GetFullName(PSObject psObject) { if (psObject.BaseObject is CmdletInfo) { return(CmdletInfo.GetFullName((CmdletInfo)psObject.BaseObject)); } PSPropertyInfo property1 = psObject.Properties["Name"]; PSPropertyInfo property2 = psObject.Properties["PSSnapIn"]; string cmdletName = property1 == null ? "" : (string)property1.Value; return(CmdletInfo.GetFullName(property2 == null ? "" : (string)property2.Value, cmdletName)); }
private static string GetFullName(CmdletInfo cmdletInfo) => CmdletInfo.GetFullName(cmdletInfo.ModuleName, cmdletInfo.Name);