Repository navigation
Select-String: Add OnlyMatching parameter to return only the actual matching value - #10696
Chris Gardner (ChrisLGardner) wants to merge 5 commits into
Conversation
|
PoshChan-Bot (@PoshChan) please retry Linux |
|
Rain Sallow (/u/ta11ow) (@vexx32), successfully started retry of |
|
I know the Personally I feel like something along the lines of What do you guys think, Steve Lee (@SteveL-MSFT)? 🙂 |
Rain Sallow (/u/ta11ow) (vexx32)
left a comment
There was a problem hiding this comment.
Nice and straightforward; couple questions on the behaviour. From the linked issue, it sounds like we should be returning the text from all match instances on the line?
There was a problem hiding this comment.
| public SwitchParameter OnlyMatching { get; set; } | |
| [Alias('o')] | |
| public SwitchParameter OnlyMatching { get; set; } |
We may want to add the explicit alias here as mentioned in the related issue.
There was a problem hiding this comment.
Added the alias.
There was a problem hiding this comment.
I think the alias should be om which is much less ambiguous (-o matches every param that starts with o) and is consistent with -ob for -OutBuffer and -ov for OutVariable.
There was a problem hiding this comment.
Keith Hill (@rkeithhill) I'd agree, but I think the intent in the original issue was to match grep's existing -o parameter.
There was a problem hiding this comment.
Considering all the parameters on Select-String that do not match grep parameters, is it worth it to try to force-fit just this one?
There was a problem hiding this comment.
I agree that -om is more in keeping with the PowerShell style. Does PowerShellTeam have a preference for what it should be?
There was a problem hiding this comment.
I too agree that -om is better; to get a definitive ruling the committee would need to be pinged, but we mere mortals can't do that, I think; Steve Lee (@SteveL-MSFT), any thoughts?
Rain Sallow (/u/ta11ow) (@vexx32), re returning the text from all match instances on the line with -AllMatches: yes, that was the intent; it's how grep -o does it too (albeit invariably); e.g., 'foo' | grep -o 'o'
|
One other thing to implement:
Note that, similarly, the currently permitted but pointless combination of |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
PR Summary
PR Context
Issue #7712 wanted a
-OnlyMatchingswitch to allow Select-String to only return the text that matched rather than either the full MatchInfo object (default behaviour) or the Line (-Rawbehaviour). This is the initial implementation of that.The issue does suggest allowing this switch to avoid the primary code path that creates the MatchInfo objects in the first place to improve performance since they aren't actually used in the output at all, I'd like to add that functionality but it's a bit beyond my abilities right now but I'll look into it and see if I can add that in either before this PR is merged or in a future PR if the team feels it's a needed improvement.
I had thought to add a parameter set for this new parameter since it doesn't make sense to be able to use both
-Rawand-OnlyMatchingbut that broke parameter binding in a way I didn't expect and wasn't able to see why it would. I can add that back in as part of this PR and try to resolve it should it be required.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.