-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Get-Content -Head and -Tail disallow negative values and cleanup #19715
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ad5957e
TotalCount {get; set;}
CarloToso fdf3335
Tail { get; set; }
CarloToso 055da9f
Add comment Tail
CarloToso fe59996
add {} while, for
CarloToso 19ba389
remove remainder
CarloToso 4ba3554
Add {} if
CarloToso f74f1e8
remove space
CarloToso 4d2459b
var, Logs
CarloToso 777d526
fast return
CarloToso c60a839
remove unnecessary if
CarloToso c4d1b51
fix comment
CarloToso c5729b1
capitalize comment
CarloToso 174ad16
edit comment
CarloToso 434dfe8
Add Tests
CarloToso 727d53a
Add {}
CarloToso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
TotalCount {get; set;}
- Loading branch information
commit ad5957e6c2015ad778244b38310cf725da073733
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,22 +35,9 @@ public class GetContentCommand : ContentCommandBase | |
/// value is -1 which means read all the content. | ||
/// </summary> | ||
[Parameter(ValueFromPipelineByPropertyName = true)] | ||
[ValidateRange(0, long.MaxValue)] | ||
[Alias("First", "Head")] | ||
public long TotalCount | ||
{ | ||
get | ||
{ | ||
return _totalCount; | ||
} | ||
|
||
set | ||
{ | ||
_totalCount = value; | ||
_totalCountSpecified = true; | ||
} | ||
} | ||
|
||
private bool _totalCountSpecified = false; | ||
public long TotalCount { get; set; } = -1; | ||
|
||
/// <summary> | ||
/// The number of content items to retrieve from the back of the file. | ||
|
@@ -98,15 +85,6 @@ internal override object GetDynamicParameters(CmdletProviderContext context) | |
|
||
#endregion Parameters | ||
|
||
#region parameter data | ||
|
||
/// <summary> | ||
/// The number of content items to retrieve. | ||
/// </summary> | ||
private long _totalCount = -1; | ||
|
||
#endregion parameter data | ||
|
||
#region Command code | ||
|
||
/// <summary> | ||
|
@@ -116,7 +94,7 @@ protected override void ProcessRecord() | |
{ | ||
// TotalCount and Tail should not be specified at the same time. | ||
// Throw out terminating error if this is the case. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment seems wrong - it doesn't look like a terminating error |
||
if (_totalCountSpecified && _tailSpecified) | ||
if (TotalCount != -1 && _tailSpecified) | ||
{ | ||
string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, "TotalCount", "Tail"); | ||
ErrorRecord error = new(new InvalidOperationException(errMsg), "TailAndHeadCannotCoexist", ErrorCategory.InvalidOperation, null); | ||
|
@@ -209,7 +187,7 @@ protected override void ProcessRecord() | |
// I am using TotalCount - countToRead so that I don't | ||
// have to worry about overflow | ||
|
||
if ((TotalCount > 0) && (countToRead == 0 || (TotalCount - countToRead < countRead))) | ||
if (TotalCount > 0 && (countToRead == 0 || TotalCount - countToRead < countRead)) | ||
{ | ||
countToRead = TotalCount - countRead; | ||
} | ||
|
@@ -256,7 +234,7 @@ protected override void ProcessRecord() | |
WriteContentObject(results, countRead, holder.PathInfo, currentContext); | ||
} | ||
} | ||
} while (results != null && results.Count > 0 && ((TotalCount < 0) || countRead < TotalCount)); | ||
} while (results != null && results.Count > 0 && (TotalCount < 0 || countRead < TotalCount)); | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, I wonder if this should be just be
long? TotalCount