public static Variant[] ToVariants(this CommandInfo info, PsHelpInfo helpInfo) { var metadata = new CommandMetadata(info); var privateCmdletName = metadata.Name.Split('!').First(); var parts = privateCmdletName.Split('_'); return(parts.Length > 1 ? new[] { new Variant(parts[0], parts[1], info, metadata, helpInfo: helpInfo) } // Process multiple parameter sets, so we declare a variant per parameter set. : info.ParameterSets.Select(ps => new Variant(privateCmdletName, ps.Name, info, metadata, true, helpInfo)).ToArray()); }
public Variant(string cmdletName, string variantName, CommandInfo info, CommandMetadata metadata, bool hasParameterSets = false, PsHelpInfo helpInfo = null) { CmdletName = cmdletName; VariantName = variantName; Info = info; HelpInfo = helpInfo ?? new PsHelpInfo(); Metadata = metadata; HasParameterSets = hasParameterSets; IsFunction = Info.CommandType == CommandTypes.Function; PrivateModuleName = Info.Source; PrivateCmdletName = Metadata.Name; SupportsShouldProcess = Metadata.SupportsShouldProcess; SupportsPaging = Metadata.SupportsPaging; Attributes = this.ToAttributes(); Parameters = this.ToParameters().OrderBy(p => p.OrderCategory).ThenByDescending(p => p.IsMandatory).ToArray(); IsInternal = Attributes.OfType <InternalExportAttribute>().Any(); IsDoNotExport = Attributes.OfType <DoNotExportAttribute>().Any(); CmdletOnlyParameters = Parameters.Where(p => !p.Categories.Any(c => c == ParameterCategory.Azure || c == ParameterCategory.Runtime)).ToArray(); Profiles = Attributes.OfType <ProfileAttribute>().SelectMany(pa => pa.Profiles).ToArray(); }