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

Add the converter for text tables to the repository #29

Closed
wants to merge 18 commits into from

Conversation

JamesWTruher
Copy link
Contributor

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 cmdlet

PR Context

build.ps1 Show resolved Hide resolved
build.ps1 Outdated Show resolved Hide resolved
build.ps1 Show resolved Hide resolved
src/Microsoft.PowerShell.TextUtility.psd1 Outdated Show resolved Hide resolved
)
PrivateData = @{
PSData = @{
LicenseUri = 'https://github.com/PowerShell/TextUtility/blob/main/LICENSE'
ProjectUri = 'https://github.com/PowerShell/TextUtility'
ReleaseNotes = 'Initial release'
Prerelease = 'Preview1'
Prerelease = 'Preview2'
Copy link
Member

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

Copy link
Contributor Author

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

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.

}
}

/*
Copy link
Member

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

Copy link
Contributor Author

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

public SwitchParameter NoHeader { get; set; }

[Parameter()]
public SwitchParameter AsPsObject { get; set; }
Copy link
Member

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

public int MaximumWidth { get; set; } = 200;

[Parameter()]
public int WindowSize { get; set; } = 0; // 0 is all
Copy link
Member

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?

Copy link
Contributor Author

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

{
if (data[j] is string)
{
// TODO: json encode the string
Copy link
Member

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?

Copy link
Contributor Author

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

return ColumnInfoList;
}

// TODO: still not right
Copy link
Member

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?

Copy link
Contributor Author

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

JamesWTruher and others added 9 commits February 21, 2023 15:06
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
Copy link
Member

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

Copy link
Contributor Author

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'
Copy link
Member

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")]

Choose a reason for hiding this comment

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

Suggested change
[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; }

Choose a reason for hiding this comment

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

Suggested change
public string[] Typename { get; set; }
public string[] TypeName { get; set; }

public int[] ColumnOffset { get; set; }

[Parameter()]
public SwitchParameter Convert { get; set; }

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.

Copy link
Contributor Author

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" >

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" = "============" },

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@JamesWTruher
Copy link
Contributor Author

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.

JamesWTruher added a commit to JamesWTruher/TextUtility that referenced this pull request Jun 21, 2023
Change name to ConvertFrom-TextTable.
Remove Preview tag (since we're still a 0.x version).
Change Convert parameter To ConvertPropertyValue, Typename to TypeName.
JamesWTruher added a commit that referenced this pull request Jun 28, 2023
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants