Skip to content

Conversation

Splaxi
Copy link
Contributor

@Splaxi Splaxi commented Nov 5, 2018

No description provided.

Copy link
Member

@FriedrichWeinmann FriedrichWeinmann left a comment

Choose a reason for hiding this comment

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

Heya, thanks for that command :)
See comments for specific feedback.

Other than those:

Display Style

Have you considered writing the actual display text using Write-PSFHostColor rather than Write-PSFMessage?
That would allow you to avoid all the message decorations (Timestamp and command name)
After all, those aren't really messages you are writing - it's console display, designed to visualize information to the user.

- ShowParameters

.PARAMETER IncludeHelp
Switch to instruct the cmdlet / function to output a simple guide with the colors in it
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 this parameter should be named -Legend instead, as that's what it really enables

Also the description is slightly confusing:

  • The switch part is redundant (the fact that it is a switch is shown as the type behind the name when calling help)
  • cmdlet / function differentiation is not a subject needed
  • Referring to the command you are explaining is counter-intuitive (we already are explaining this command, so what is it referring to?)

Instead something like:

Include a legend explaining the color mapping / meaning

Would be very clear and concise about its purpose

Switch to instruct the cmdlet / function to output a simple guide with the colors in it

.EXAMPLE
PS C:\> Show-PSMDSyntax -CommandText 'Import-D365Bacpac -ImportModeTier2 -SqlUser "sqladmin" -SqlPwd "XyzXyz" -BacpacFile2 "C:\temp\uat.bacpac"' -Mode "Validate"
Copy link
Member

Choose a reason for hiding this comment

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

General note on examples:
Those should be executable without any extra module dependency, if practicable (something I myself have sometimes gotten wrong, but fix where I touch it). I know it's a copy from a command in your own module (where no extra dependency is added obviously, but would appreciate the update none-the-less

This will display all the parameter sets and their individual parameters.

.NOTES
Author: Mötz Jensen (@Splaxi)
Copy link
Member

Choose a reason for hiding this comment

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

Insufficient notes.
To properly credit your contribution, please also include a link to twitter and your github repository where you copied it from.
I totally want people to find your other cool stuff, if they are interested enough to look at the notes :)


[Parameter(Mandatory = $true, Position = 2)]
[ValidateSet('Validate', 'ShowParameters')]
[string] $Mode,
Copy link
Member

Choose a reason for hiding this comment

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

Why is this parameter mandatory?
Wouldn't a default value of 'Validate' be more convenient for the user?
Also: Why include modes at all?
I have yet to see a meaningful difference between the modes.

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 agree on the default value, that it should be validate.

The main reason for the 2 modes is maybe a bit vague, but the validate shows asterisk all around the output. From a user perspective I thought that it might confuse people the first few times, until the understood the function. Let's visit this when we have nailed the rest.

return
}
}
else {
Copy link
Member

Choose a reason for hiding this comment

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

Terminating loop conditions should not be placed in a trailing else block - move above the current if position, save yourself a nested braces level and make the code more readable.

}
}
else {
Write-PSFMessage -Level Host -Message "The function was unable to get the help of the command. Make sure that the command name is valid and try again."
Copy link
Member

Choose a reason for hiding this comment

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

Terminating loop conditions should not be placed in a trailing else block - move above the current if position, save yourself a nested braces level and make the code more readable.

"ShowParameters" {
foreach ($parmSet in (Get-Command $commandName).ParameterSets) {
# (Get-Command $commandName).ParameterSets | ForEach-Object {
$null = $sb = New-Object System.Text.StringBuilder
Copy link
Member

Choose a reason for hiding this comment

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

What is the point in this null-assignment?

}

foreach ($parmSet in (Get-Command $commandName).ParameterSets) {
$null = $sb = New-Object System.Text.StringBuilder
Copy link
Member

Choose a reason for hiding this comment

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

Superfluous null-assignment


if ($parmFoundInCommandText) {
$color = "$colorFoundAsterisk"
$null = $sb.Append("<c='$color'>* </c>")
Copy link
Member

Choose a reason for hiding this comment

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

This can be compacted to:

$null = $sb.Append("<c='$colorFoundAsterisk'>* </c>")

@FriedrichWeinmann
Copy link
Member

Another thing I noted:
It will not notify when you can no longer resolve to at least one parameterset:

Show-PSMDSyntax -CommandText 'Get-Help -Name foo -Examples -Parameter bar' -Mode Validate

This will happily show all parametersets.

It may be a good idea to warn about impossible parameter sets.

Maybe even separate the parameter sets as they are displayed between parametersets still possible and parametersets no longer possible (the impossible ones displaying the parameters that cannot be fit into them in a special color)

@Splaxi
Copy link
Contributor Author

Splaxi commented Nov 12, 2018

I hadn't been working with Write-PSFHostColor earlier and you were away, so I just started with what i had of available tools. That should be fixed now.

Regarding the parametersets and impossible ones - that was actually not part of the plan, but I like the idea. That might just require a bit more understanding from my side. I'll give it a look.

@Splaxi
Copy link
Contributor Author

Splaxi commented Nov 12, 2018

Did most of the updates. Let us see how it goes. Then we could discuss more about the invalid parametersets.

@FriedrichWeinmann FriedrichWeinmann merged commit 730cb8c into PowershellFrameworkCollective:development Nov 25, 2018
@FriedrichWeinmann
Copy link
Member

Thanks for all the work on this, merged it into dev, will be in the next release :)

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.

2 participants