Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] adding select-string -raw #8962

Closed

Conversation

david-wang24
Copy link

@david-wang24 david-wang24 commented Feb 24, 2019

PR Summary

Added -Raw switch to select-string for convenience. Issue #7713.

PR Context

Resolves #7713.

PR Checklist

@msftclas
Copy link

msftclas commented Feb 24, 2019

CLA assistant check
All CLA requirements met.

Copy link
Collaborator

@rjmholt rjmholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good -- have left some comments about changes to make

@@ -93,6 +107,10 @@ public class MatchInfo
/// <value>The text of the matching line.</value>
public string Line { get; set; } = string.Empty;


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these newlines

@@ -101,6 +119,9 @@ public class MatchInfo
/// </remarks>
/// </summary>
/// <value>The file name.</value>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these newlines

@TylerLeonhardt
Copy link
Member

This is a student at HackIllinois. @rjmholt and I are working with the students here and are reviewing PRs that they send.

…chString.cs

Co-Authored-By: david-wang24 <42791457+david-wang24@users.noreply.github.com>
Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lefts a few comments! This is coming along 😄

/// </summary>
internal MatchInfo(bool useRaw, bool useColor, int matchIndex, int matchLength)
{
isRaw = useRaw;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isRaw = useRaw;
_isRaw = useRaw;

@@ -226,7 +242,15 @@ public string ToString(string directory)
// enable context-tracking.
if (Context == null)
{
return FormatLine(Line, this.LineNumber, displayPath, EmptyPrefix);
if(isRaw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(isRaw)
if(_isRaw)

@@ -235,14 +259,37 @@ public string ToString(string directory)
int displayLineNumber = this.LineNumber - Context.DisplayPreContext.Length;
foreach (string contextLine in Context.DisplayPreContext)
{
lines.Add(FormatLine(contextLine, displayLineNumber++, displayPath, ContextPrefix));

if(isRaw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(isRaw)
if(_isRaw)

}

lines.Add(FormatLine(Line, displayLineNumber++, displayPath, MatchPrefix));

if(isRaw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(isRaw)
if(_isRaw)

foreach (string contextLine in Context.DisplayPostContext)
{
lines.Add(FormatLine(contextLine, displayLineNumber++, displayPath, ContextPrefix));
if(isRaw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(isRaw)
if(_isRaw)

@rjmholt rjmholt added the Hacktoberfest Potential candidate to participate in Hacktoberfest label Feb 25, 2019
@TylerLeonhardt
Copy link
Member

Sorry for the delay, @david-wang24! This is great work! I do have a thought about the implementation.

As we know, in PowerShell, we typically pass around objects everywhere. Into functions, into the pipeline, into variables, everywhere!

What Select-String does today is it returns objects as well of type MatchInfo. But you already knew that 😁

The addition of a -Raw flag in my mind (and @mklement0 who originally opened the issue) is that -Raw would tell Select-String to actually return strings instead of MatchInfos.

What your current implementation does is still returning MatchInfo objects but it's changing the behavior of MatchInfo.ToString() to look like it's only returning the matching lines.

It's still really impressive what you've done so far, but we should look at the problem from a different angle.

Does that make sense? Let me know if you're interested in still working on this 😊no rush

@powercode
Copy link
Collaborator

powercode commented Mar 9, 2019

I think we should resist the temptation to add nifty switches. The same thing can be accomplished with

… | % Line

@vexx32
Copy link
Collaborator

vexx32 commented Mar 9, 2019

@powercode per the discussion in this PR, that would return the complete matching lines, not just the matched strings from each MatchInfo object.

@mklement0
Copy link
Contributor

mklement0 commented Mar 10, 2019

Actually, @vexx32, -Raw is indeed about returning full lines, whereas it is -OnlyMatching (#8965) is about only returning what was matched.

@powercode, adding the -Raw switch was greenlit in #7713, and -OnlyMatching was green-lit in #7712. If you feel these features shouldn't have been approved, please voice your concerns there.

To recap the rationale:

@stale
Copy link

stale bot commented Apr 10, 2019

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale bot added the Stale label Apr 10, 2019
@stale
Copy link

stale bot commented Apr 20, 2019

This PR has been automatically closed because it is stale. If you wish to continue working on the PR, please first update the PR, then reopen it.
Thanks again for your contribution.
Community members are welcome to grab these works.

@stale stale bot closed this Apr 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest Potential candidate to participate in Hacktoberfest Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a switch to Select-String that makes it return just strings for convenience and performance
7 participants