-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add the converter for text tables to the repository #29
Conversation
Fix some tests in Compare-Text.
Also create xml result file.
Small changes in text parser.
) | ||
PrivateData = @{ | ||
PSData = @{ | ||
LicenseUri = 'https://github.com/PowerShell/TextUtility/blob/main/LICENSE' | ||
ProjectUri = 'https://github.com/PowerShell/TextUtility' | ||
ReleaseNotes = 'Initial release' | ||
Prerelease = 'Preview1' | ||
Prerelease = 'Preview2' |
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.
I wonder if we should just leave this as Preview
since we're updating the version anyways
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.
sure - I'll do that
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.
Can we please remove the prerelease label? This module hasn't reached 1.0 to indicate stable yet. Not having any stable versions of a package is a hassle to install since -Prerelease
has to be used. The main benefit to having prerelease in my opinion is when a stable version already exists.
src/code/TextTableParser.cs
Outdated
} | ||
} | ||
|
||
/* |
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.
If you're keeping this commented out code, should have a comment explaining why otherwise remove it
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.
now that it's in a commit, I don't need it any more
src/code/TextTableParser.cs
Outdated
public SwitchParameter NoHeader { get; set; } | ||
|
||
[Parameter()] | ||
public SwitchParameter AsPsObject { get; set; } |
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.
I think it makes more sense to output PSObject by default and have AsJson
to opt-in
src/code/TextTableParser.cs
Outdated
public int MaximumWidth { get; set; } = 200; | ||
|
||
[Parameter()] | ||
public int WindowSize { get; set; } = 0; // 0 is all |
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.
WindowSize
is the number of rows to analyze? If so, maybe call it AnalyzeRowCount
?
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.
I used WindowSize
to be closer to Compare-Object
SyncWindow
but I like AnalyzeRowCount best, thanks
src/code/TextTableParser.cs
Outdated
{ | ||
if (data[j] is string) | ||
{ | ||
// TODO: json encode the string |
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.
I don't understand this TODO, isn't line 315 encoding as json?
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.
yah - I missed cleaning this up
src/code/TextTableParser.cs
Outdated
return ColumnInfoList; | ||
} | ||
|
||
// TODO: still not right |
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.
Can you specify what isn't right?
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.
it's mostly right now - another missed cleanup
Co-authored-by: Steve Lee <slee@microsoft.com>
`Array.Fill` not available, so we will do it manually.
Update build to default to debug configuration.
Also take advantage of Pester's ability to compare arrays.
Add an additional test for OutputRendering = 'PlainText'
Remove a number of misleading comments. Change to be PSObject output by default (now we have an AsJson parameter). Change WindowSize parameter to AnalyzeRowCount. Fix test to not clone the convertArgs hashtable before modifying. Remove extraneous using statements. Build for netstandard2.0 rather than 2.1.
@@ -4,6 +4,7 @@ obj/ | |||
out/ | |||
project.lock.json | |||
.DS_Store | |||
Microsoft.PowerShell.TextUtility.xml |
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.
is this the xml help generated during build? we should just exclude the build folder than this specific file
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.
no, it's generated by Invoke-Pester
when -test
is used with build
@@ -4,7 +4,7 @@ parameters: | |||
jobDisplayName: 'Run test' | |||
|
|||
jobs: | |||
- job: '${{ parameters.jobName }}_netstandard20' | |||
- job: '${{ parameters.jobName }}_netstandard21' |
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.
didn't you fix this to be netstandard20 compatible?
} | ||
} | ||
|
||
[Cmdlet("Convert","TextTable")] |
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.
[Cmdlet("Convert","TextTable")] | |
[Cmdlet("ConvertFrom","TextTable")] |
During the community call it was suggested to change verb to ConvertFrom
.
public int HeaderLine { get; set; } = 0; // Assume the first line is the header | ||
|
||
[Parameter()] | ||
public string[] Typename { get; set; } |
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.
public string[] Typename { get; set; } | |
public string[] TypeName { get; set; } |
public int[] ColumnOffset { get; set; } | ||
|
||
[Parameter()] | ||
public SwitchParameter Convert { get; set; } |
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.
I don't have a good suggestion on this but the parameter name is ambiguous especially since the verb is Convert
maybe something like ConvertPropertyValue
or ConvertPropertyType
or CastPropertyValue
or CastPropertyType
.
Something to indicate from the parameter name what is being changed in the output.
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.
I liked ConvertPropertyValue
the best, so that's what I went with.
@@ -17,6 +17,9 @@ | |||
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-*"> | |||
<PrivateAssets>all</PrivateAssets> | |||
</PackageReference> | |||
<PackageReference Include="System.Text.Json" Version="6.0.6" > |
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.
Since this module supports PS 5.1 ensure that System.Text.Json
dll gets included in the module.
FileName = "tasklist.01.txt" | ||
convertArgs = @{} | ||
Rows = 46 | ||
Results = @{ ROW = 0; "Image_Name" = "========================="; "PID" = "========"; "Session_Name" = "================"; "Session#" = "==========="; "Mem_Usage" = "============" }, |
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.
The conversion process should check for header symbols and remove them from parsed output. For example, if all the properties of a row contain the same character (=
, -
, _
, etc) it should be removed.
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.
it's the etc I'm worried about. Right now, I'm not spending any time determining the content of the data, just the column delineation. There might be a performance penalty if I have to carefully inspect the data. Also, I need those separators as part of the determination of what a column, so I can't preprocess it away.
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.
I've opened #34 to track
I made too many changes in the process of getting to a successful release build, so I'm closing this and opening a new PR. @ThomasNieto I've incorporated nearly all your requests into the new branch. I still need to address #29 (comment) , though, I'm concerned about over elimination (don't want to throw away input which might turn into valid data). I may leave that to a future preview. |
Change name to ConvertFrom-TextTable. Remove Preview tag (since we're still a 0.x version). Change Convert parameter To ConvertPropertyValue, Typename to TypeName.
* Initial commit of text table converter with tests. * Address feedback in PR #29 (now closed). Change name to ConvertFrom-TextTable. Remove Preview tag (since we're still a 0.x version). Change Convert parameter To ConvertPropertyValue, Typename to TypeName.
PR Summary
This adds the code and tests for converting text tables to json or psobjects
Also fixed a few failing tests for the
Compare-Text
cmdletPR Context