Skip to content

Commit

Permalink
Context refactor 2 (microsoft#2525)
Browse files Browse the repository at this point in the history
  • Loading branch information
BernieWhite authored Sep 3, 2024
1 parent 1fd2d7c commit e05ff57
Show file tree
Hide file tree
Showing 12 changed files with 558 additions and 553 deletions.
5 changes: 4 additions & 1 deletion src/PSRule/Configuration/BindingOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
namespace PSRule.Configuration;

/// <summary>
/// Options that affect property binding of TargetName and TargetType.
/// Options that configure property binding.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options"/>.
/// </remarks>
public sealed class BindingOption : IEquatable<BindingOption>, IBindingOption
{
private const bool DEFAULT_IGNORECASE = true;
Expand Down
61 changes: 61 additions & 0 deletions src/PSRule/Configuration/IBindingOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,67 @@

namespace PSRule.Configuration;

/// <summary>
/// Options that configure property binding.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options"/>.
/// </remarks>
public interface IBindingOption : IOption
{
/// <summary>
/// One or more custom fields to bind.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options#bindingfield"/>.
/// </remarks>
FieldMap Field { get; }

/// <summary>
/// Determines if custom binding uses ignores case when matching properties.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options#bindingignorecase"/>.
/// </remarks>
bool? IgnoreCase { get; }

/// <summary>
/// Configures the separator to use for building a qualified name.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options#bindingnameseparator"/>.
/// </remarks>
string NameSeparator { get; }

/// <summary>
/// Determines if binding prefers target info provided by the object over custom configuration.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options#bindingprefertargetinfo"/>.
/// </remarks>
bool? PreferTargetInfo { get; }

/// <summary>
/// Property names to use to bind TargetName.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options#bindingtargetname"/>.
/// </remarks>
string[] TargetName { get; }

/// <summary>
/// Property names to use to bind TargetType.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options#bindingtargettype"/>.
/// </remarks>
string[] TargetType { get; }

/// <summary>
/// Determines if a qualified TargetName is used.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options#bindingusequalifiedname"/>.
/// </remarks>
bool? UseQualifiedName { get; }
}
38 changes: 1 addition & 37 deletions src/PSRule/Pipeline/GetTargetPipelineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,6 @@ public override IPipeline Build(IPipelineWriter writer = null)
/// <inheritdoc/>
protected override PipelineInputStream PrepareReader()
{
if (!string.IsNullOrEmpty(Option.Input.ObjectPath))
{
AddVisitTargetObjectAction((sourceObject, next) =>
{
return PipelineReceiverActions.ReadObjectPath(sourceObject, next, Option.Input.ObjectPath, true);
});
}

if (Option.Input.Format == InputFormat.Yaml)
{
AddVisitTargetObjectAction((sourceObject, next) =>
{
return PipelineReceiverActions.ConvertFromYaml(sourceObject, next);
});
}
else if (Option.Input.Format == InputFormat.Json)
{
AddVisitTargetObjectAction((sourceObject, next) =>
{
return PipelineReceiverActions.ConvertFromJson(sourceObject, next);
});
}
else if (Option.Input.Format == InputFormat.Markdown)
{
AddVisitTargetObjectAction((sourceObject, next) =>
{
return PipelineReceiverActions.ConvertFromMarkdown(sourceObject, next);
});
}
else if (Option.Input.Format == InputFormat.PowerShellData)
{
AddVisitTargetObjectAction((sourceObject, next) =>
{
return PipelineReceiverActions.ConvertFromPowerShellData(sourceObject, next);
});
}
return new PipelineInputStream(VisitTargetObject, _InputPath, GetInputObjectSourceFilter(), Option);
return new PipelineInputStream(_InputPath, GetInputObjectSourceFilter(), Option);
}
}
29 changes: 29 additions & 0 deletions src/PSRule/Pipeline/IPipelineBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using PSRule.Configuration;

namespace PSRule.Pipeline;

/// <summary>
/// A helper to build a PSRule pipeline.
/// </summary>
public interface IPipelineBuilder
{
/// <summary>
/// Configure the pipeline with options.
/// </summary>
IPipelineBuilder Configure(PSRuleOption option);

/// <summary>
/// Configure the pipeline to use a specific baseline.
/// </summary>
/// <param name="baseline">A baseline option or the name of a baseline.</param>
void Baseline(BaselineOption baseline);

/// <summary>
/// Build the pipeline.
/// </summary>
/// <param name="writer">Optionally specify a custom writer which will handle output processing.</param>
IPipeline Build(IPipelineWriter writer = null);
}
2 changes: 2 additions & 0 deletions src/PSRule/Pipeline/IPipelineReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace PSRule.Pipeline;

#nullable enable

internal interface IPipelineReader
{
int Count { get; }
Expand Down
38 changes: 1 addition & 37 deletions src/PSRule/Pipeline/InvokePipelineBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,42 +131,6 @@ private static bool IsBlocked(string path)

protected override PipelineInputStream PrepareReader()
{
if (!string.IsNullOrEmpty(Option.Input.ObjectPath))
{
AddVisitTargetObjectAction((sourceObject, next) =>
{
return PipelineReceiverActions.ReadObjectPath(sourceObject, next, Option.Input.ObjectPath, true);
});
}

if (Option.Input.Format == InputFormat.Yaml)
{
AddVisitTargetObjectAction((sourceObject, next) =>
{
return PipelineReceiverActions.ConvertFromYaml(sourceObject, next);
});
}
else if (Option.Input.Format == InputFormat.Json)
{
AddVisitTargetObjectAction((sourceObject, next) =>
{
return PipelineReceiverActions.ConvertFromJson(sourceObject, next);
});
}
else if (Option.Input.Format == InputFormat.Markdown)
{
AddVisitTargetObjectAction((sourceObject, next) =>
{
return PipelineReceiverActions.ConvertFromMarkdown(sourceObject, next);
});
}
else if (Option.Input.Format == InputFormat.PowerShellData)
{
AddVisitTargetObjectAction((sourceObject, next) =>
{
return PipelineReceiverActions.ConvertFromPowerShellData(sourceObject, next);
});
}
return new PipelineInputStream(VisitTargetObject, _InputPath, GetInputObjectSourceFilter(), Option);
return new PipelineInputStream(_InputPath, GetInputObjectSourceFilter(), Option);
}
}
Loading

0 comments on commit e05ff57

Please sign in to comment.