Closed plastikfan closed 3 years ago
Move-Match:
if ($Start.ToBool()) {
$result = $replaceWith + $patternRemoved;
}
elseif ($End.ToBool()) {
$result = $patternRemoved + $replaceWith;
}
elseif ($PSBoundParameters.ContainsKey('Anchor')) {
This code needs to change so that we check for the anchor first before Start/End. Inside Anchor processing, we check for Start/End if the Anchor match fails.
Currently we have the following parameter sets for Rename-Many:
Since Start/End can be specified with Anchor, we might initially think we can resolve this all into the same parameters set. We can't do this because Start can't be specified at the same time as End.
However perhaps, we can now get rid of MoveToAnchor and leave Anchor to be a member of MoveToStart/MoveToEnd. But those parameter sets feel like they're misnomas. So We could change the names to:
⚠️ALERT: made a change to build script so the tag is read from environment variable $env:tag
Propagate to other modules and gist
Using the current parameters only, we can't implement thsi feature. This is because this results in defining parameter sets that can't be distinuished from one another if we only specify Pattern/Start or Pattern/End.
Instead we need to define new unique parameters:
ElseStart, ElseEnd which would be invoked as:
Rename-Many -Pattern 'foo' -Anchor 'bar' -ElseStart
or
Rename-Many -Pattern 'foo' -Anchor 'bar' -ElseEnd
or we could:
Rename-Many -Pattern 'foo' -Anchor 'bar' -AnchorElse -Start
or
Rename-Many -Pattern 'foo' -Anchor 'bar' -AnchorElse -End
repeating the Anchor in the name feels overly verbose.
or:
or we could:
Rename-Many -Pattern 'foo' -Anchor 'bar' -Else -Start
or
Rename-Many -Pattern 'foo' -Anchor 'bar' -Else -End
The only issue with this is that Else is not clearly linked to Anchor, but maybe it doesnt have to be.
This does actually read better.
or:
Rename-Many -Pattern 'foo' -Anchor 'bar' -ElseStart
or
Rename-Many -Pattern 'foo' -Anchor 'bar' -ElseEnd
which requires fewer parameters. This is gonna be the chosen option.
The problem that requires solving now is that where we invoke Renam-Many with say -Pattern and -Copy then this is now ambiguous as to what parameter set it refers to. The same I assume would applie to say specifying -Pattern and -With.
I think we need to abandon Parameters partially, they are proving not to be a scalable soution for parameter validation. The solution to fix this with parameter sets would require the introduction of many more parameters and sets to the point that it makes the unfeasibly complex. We can do this better ourselves.
The parameters Copy/With/Paste are so generic that they are a member of so many parameter sets. The only rule that should apply to these is:
So introduce have PasteFormat, WithFormat sets.
But this doesnt fix -Pattern and -Copy.
So instead of using PasteFormat, WithFormat sets, we can remove all parameter sets from Copy/With/Paste and then apply this rules manually.
This issue should be suspended until issue #114 has been resolved.
git stash: How to use git stash (and when not to use it) by Nick Ang
This was implemented using 2 new parameters AnchorStart and AnchorEnd defined in 2 new parameter sets: HybridStart and HybridEnd.
So if the anchor doesnt match, then the pattern match will be moved according to if Start or End is specified.