Add parameter -Group to Get-Verb#2789
Conversation
|
Hi @dchristian3188, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! The agreement was validated by Microsoft and real humans are currently evaluating your PR. TTYL, MSBOT; |
There was a problem hiding this comment.
I'd rather see enum here instead string.
There was a problem hiding this comment.
@iSazonov What do you think would be the best way to accomplish this? Currently the groups are determined by looking at the class names and removing the word verb.
[System.Reflection.IntrospectionExtensions]::GetTypeInfo([PSObject]).Assembly.ExportedTypes | Where-Object {$_.Name -match '^Verbs.'}
I could put the current groups in a validate set but is that the best for long term support?
There was a problem hiding this comment.
ValidateSet is reasonable, especially if there is an easy way to test.
I would like to see this command converted to C#.
There was a problem hiding this comment.
You can see a enum using sample in Get/Set-Alias
The enum could be placed Verbs.cs
(About 30 parameters using this.)
There was a problem hiding this comment.
thanks for the feedback. I'll get started on the changes
There was a problem hiding this comment.
@lzybkr Could you comment on the use of enum vs validate set ?
I attached the file with script and the resulting list of parameters whose type is enum (for Powershel 6 only).
Test-Params.txt
There was a problem hiding this comment.
In this case, an enum introduces a new public api.
If the only use of that enum is for parameter validation and tab completion, then ValidateSet is might be better than introducing a new api.
If we did use an enum, the parameter doesn't need to be an array, the enum could use Flags.
There was a problem hiding this comment.
@lzybkr Thanks for great comment! I was asking about using VerbGroups in Issue addressed in the PR but there were no examples. So I don't see the need for the public api at all.
lzybkr
left a comment
There was a problem hiding this comment.
Great tests!
I realize you mostly just rewrote the original function in C#, but I think the original implementation could have been better.
I realize the performance of this cmdlet really doesn't matter, but we have plenty of bad patterns that people just copy and I want to avoid introducing those patterns in addition to fixing the bad patterns over time.
There was a problem hiding this comment.
The types all start with Verbs, so you can use type.Name.Substring(5) which avoids the search that Replace would do.
There was a problem hiding this comment.
It doesn't really make sense to have BeginProcessing. This method generates a bunch of results that might be thrown away. It's better to avoid creating those results in the first place.
There was a problem hiding this comment.
After further reflection, I'm open to the proposal by @iSazonov to use an enum. It makes a lot of sense to use an enum in the objects returned by this cmdlet.
At this point, I'm just commenting (sort of thinking out loud) - I'm not requiring a change, but feel free to try it and see if it seems better.
There was a problem hiding this comment.
The field name should be identical to the value. If we added an assertion to that effect, then we could use field.Name instead.
There was a problem hiding this comment.
This list should not be necessary.
There was a problem hiding this comment.
This list should not be necessary - it should be possible to generate all results without storing any in a list.
There was a problem hiding this comment.
You will find SessionStateUtilities.MatchesAnyWildcardPattern useful in avoiding creating a list.
There was a problem hiding this comment.
More simply:
$_.FullyQualifiedErrorId | Should Be ...There was a problem hiding this comment.
Shouldn't this be ... | Should BeNullOrEmpty
There was a problem hiding this comment.
We don't use -test anywhere else, so it just looks weird here and should probably be removed.
There was a problem hiding this comment.
If the parameter was an enum with flags, you wouldn't need any special code to cover this case, we wouldn't see the group specified multiple times.
|
Got it, thanks for the review Izbkr. I'll get started on the changes. |
There was a problem hiding this comment.
(Get-Verb -Verb Add | Measure-Obj [](start = 8, length = 33)
this should be expressed as:
@(Get-Verb -Verb Add).Count | should be 1
no need to use measure-object (and the same for all of these uses of Measure-Object)
There was a problem hiding this comment.
thanks! I was trying to use (Get-Verb -Verb Add).Count but was getting null results. Didn't think of adding the "@".
There was a problem hiding this comment.
if you're not sure whether you'll get a singleton or a collection you can always add @()
There was a problem hiding this comment.
-Verb -Group Common | Should not be $null [](start = 11, length = 41)
this doesn't actually validate that you got the proper group
i think you're looking for this:
(Get-Verb -Group Common).Group | Sort-Object -uniq | Should be Common
There was a problem hiding this comment.
Get-Verb -Group FakeGroupNeverExists -ErrorAction Stop [](start = 12, length = 54)
in case this doesn't throw, you need to add:
throw "Expected error did not occur"
or similar
lzybkr
left a comment
There was a problem hiding this comment.
Looking pretty good now, just a couple more perf issues to fix.
As long as you're making these changes, you might as well use our consistent formatting, a space after if and spaces after arguments, instead of foo(arg1,arg2), use foo(arg1, arg2).
If you don't make those changes, we'll fix it later with a tool, but it's nicer to be in the habit of following the conventions of the project.
There was a problem hiding this comment.
This creates a ton of garbage - move it outside the loops.
There was a problem hiding this comment.
This can be done once per type, not once per field in the type, correct?
There was a problem hiding this comment.
that makes alot of sense, I'll get this updated.
lzybkr
left a comment
There was a problem hiding this comment.
Looks good - please fix the merge conflict so we can merge the PR.
|
Since you are using the validateset with hardcoded group names, can you add a test enumerating the possible groups and ensuring all possibilities are handled in the validateset? |
ef950cf to
579e983
Compare
| Author="Microsoft Corporation" | ||
| CompanyName="Microsoft Corporation" | ||
| Copyright="� Microsoft Corporation. All rights reserved." | ||
| Copyright="© Microsoft Corporation. All rights reserved." |
There was a problem hiding this comment.
This change should be reverted - it changes the file to UTF8 encoding without a BOM.
There was a problem hiding this comment.
Instead of reverting the change, you added a BOM.
That's a reasonable change to make (we have another PR to clean these up), but to keep this PR clean, I'd prefer you undo the change and not change the encoding.
|
Added an additional test to cover extra groups. Please let me know if any other changes are needed. |
Adding group filter to get-verb. Please reference:
#2527