public MarkdownParameterHelpInfo(PsParameterHelpInfo parameterHelpInfo, ParameterGroup parameterGroup)
        {
            Name         = parameterGroup.ParameterName;
            Description  = parameterHelpInfo.Description.NullIfEmpty() ?? parameterGroup.Description;
            Type         = parameterGroup.ParameterType;
            Position     = parameterHelpInfo.PositionText.ToUpperFirstCharacter().NullIfEmpty() ?? parameterGroup.FirstPosition?.ToString() ?? "Named";
            DefaultValue = parameterHelpInfo.DefaultValueAsString.NullIfEmpty() ?? parameterGroup.DefaultValue?.Value?.ToString() ?? "None";

            HasAllParameterSets = parameterGroup.HasAllVariants;
            ParameterSetNames   = parameterHelpInfo.ParameterSetNames.NullIfEmpty() ?? parameterGroup.Parameters.Select(p => p.VariantName).ToArray();
            Aliases             = parameterHelpInfo.Aliases.NullIfEmpty() ?? parameterGroup.Aliases;

            IsRequired                    = parameterHelpInfo.IsRequired ?? parameterGroup.IsMandatory;
            IsDynamic                     = parameterHelpInfo.IsDynamic ?? false;
            AcceptsPipelineByValue        = parameterHelpInfo.SupportsPipelineInput?.Contains("ByValue") ?? parameterGroup.ValueFromPipeline;
            AcceptsPipelineByPropertyName = parameterHelpInfo.SupportsPipelineInput?.Contains("ByPropertyName") ?? parameterGroup.ValueFromPipelineByPropertyName;
            AcceptsWildcardCharacters     = parameterGroup.SupportsWildcards;
        }
Example #2
0
        public Parameter(string variantName, string parameterName, ParameterMetadata metadata, PsParameterHelpInfo helpInfo = null)
        {
            VariantName   = variantName;
            ParameterName = parameterName;
            Metadata      = metadata;
            HelpInfo      = helpInfo ?? new PsParameterHelpInfo();

            Attributes            = Metadata.Attributes.ToArray();
            ParameterType         = Attributes.OfType <ExportAsAttribute>().FirstOrDefault()?.Type ?? Metadata.ParameterType;
            Categories            = Attributes.OfType <CategoryAttribute>().SelectMany(ca => ca.Categories).Distinct().ToArray();
            OrderCategory         = Categories.DefaultIfEmpty(ParameterCategory.Body).Min();
            DefaultValueAttribute = Attributes.OfType <PSDefaultValueAttribute>().FirstOrDefault();
            DefaultInfoAttribute  = Attributes.OfType <DefaultInfoAttribute>().FirstOrDefault();
            ParameterAttribute    = Attributes.OfType <ParameterAttribute>().FirstOrDefault(pa => pa.ParameterSetName == VariantName || pa.ParameterSetName == AllParameterSets);
            if (ParameterAttribute == null)
            {
                throw new ParsingMetadataException($"The variant '{VariantName}' has multiple parameter sets defined, which is not supported.");
            }
            SupportsWildcards          = Attributes.OfType <SupportsWildcardsAttribute>().Any();
            CompleterInfoAttribute     = Attributes.OfType <CompleterInfoAttribute>().FirstOrDefault();
            ArgumentCompleterAttribute = Attributes.OfType <ArgumentCompleterAttribute>().FirstOrDefault();

            ValueFromPipeline = ParameterAttribute.ValueFromPipeline;
            ValueFromPipelineByPropertyName = ParameterAttribute.ValueFromPipelineByPropertyName;
            Position    = ParameterAttribute.Position == Int32.MinValue ? (int?)null : ParameterAttribute.Position;
            DontShow    = ParameterAttribute.DontShow;
            IsMandatory = ParameterAttribute.Mandatory;

            var complexParameterName = ParameterName.ToUpperInvariant();
            var complexMessage       = $"{Environment.NewLine}To construct, see NOTES section for {complexParameterName} properties and create a hash table.";
            var description          = ParameterAttribute.HelpMessage.NullIfEmpty() ?? HelpInfo.Description.NullIfEmpty() ?? InfoAttribute?.Description.NullIfEmpty() ?? String.Empty;

            // Remove the complex type message as it will be reinserted if this is a complex type
            description = description.NormalizeNewLines().Replace(complexMessage, String.Empty).Replace(complexMessage.ToPsSingleLine(), String.Empty);
            // Make an InfoAttribute for processing only if one isn't provided
            InfoAttribute = Attributes.OfType <InfoAttribute>().FirstOrDefault() ?? new InfoAttribute {
                PossibleTypes = new[] { ParameterType.Unwrap() }, Required = IsMandatory
            };
            // Set the description if the InfoAttribute does not have one since they are exported without a description
            InfoAttribute.Description = String.IsNullOrEmpty(InfoAttribute.Description) ? description : InfoAttribute.Description;
            ComplexInterfaceInfo      = InfoAttribute.ToComplexInterfaceInfo(complexParameterName, ParameterType, true);
            IsComplexInterface        = ComplexInterfaceInfo.IsComplexInterface;
            Description = $"{description}{(IsComplexInterface ? complexMessage : String.Empty)}";
        }