Get-Verb: add verb descriptions and alias prefixes#4746
Get-Verb: add verb descriptions and alias prefixes#4746mirichmo merged 15 commits intoPowerShell:masterfrom
Conversation
|
@Tadas Thanks for your contribution! @lzybkr Could you please comment. Currently we use reflection and dynamically re-create |
|
|
||
| /// <summary> | ||
| /// Verb descriptions. | ||
| /// </summary> |
There was a problem hiding this comment.
Descriptions needs to be in a resx file so they can be localized.
|
|
||
| /// <summary> | ||
| /// "Build" verb alias prefix | ||
| /// </summary> |
There was a problem hiding this comment.
@HemantMahawar should probably be defining a prefix for the verbs which have none: Build, Deploy, Optimize, and Resize.
There was a problem hiding this comment.
- Build --> bd
- Deploy --> dp
- Optimize --> om
- Resize --> rz
/cc @joeyaiello
|
@Tadas @iSazonov - we don't need a cache for these new properties and reflection is fine -
|
| VerbInfo verb = new VerbInfo(); | ||
| verb.Verb = field.Name; | ||
|
|
||
| FieldInfo aliasField = typeof(VerbAliasPrefixes).GetField(field.Name); |
There was a problem hiding this comment.
Suggestion: Refactor this as static method in the associated class. It will provide more flexibility with refactoring, should it be necessary.
|
|
||
| verb.Group = groupName; | ||
|
|
||
| FieldInfo descriptionField = typeof(VerbDescriptions).GetField(field.Name); |
There was a problem hiding this comment.
The description lookup should be a static method in the VerbDescription class; especially since the strings should be in a resx file to enable localization.
| public const string Write = "Adds information to a target"; | ||
| public static string GetVerbDescription(string verb) | ||
| { | ||
| return VerbDescriptionStrings.ResourceManager.GetString(verb + "VerbDescription"); |
There was a problem hiding this comment.
I do not see the benefits of "verbdescription". I think we could remove it.
|
|
||
| It "Should have descriptions for all verbs" { | ||
| $noDesc = Get-Verb | Where-Object { [string]::IsNullOrEmpty($_.Description) } | ||
| $noDesc | Should be $null |
There was a problem hiding this comment.
For "all verbs" we should count.
There was a problem hiding this comment.
You mean I should test for $verbsWithDescription.count | Should be $allVerbs.count or do you mean something else?
There was a problem hiding this comment.
Yes. We should count verbs and verbs with Description.
|
|
||
| It "Should have alias prefixes for all verbs" { | ||
| $noPrefix = Get-Verb | Where-Object { [string]::IsNullOrEmpty($_.AliasPrefix) } | ||
| $noPrefix | Should be $null |
There was a problem hiding this comment.
The same. We should count verbs and verbs with AliasPrefix.
| /// <summary> | ||
| /// Gets verb prefix | ||
| /// </summary> | ||
| public static string GetVerbPrefix(string verb) |
There was a problem hiding this comment.
Maybe GetVerbAliasPrefix ?
|
I've just noticed that Copy and Complete verbs have the same alias "cp". Should those be unique? |
|
@HemantMahawar @joeyaiello what do you think of the duplicate verb prefixes for Complete and Copy? |
|
|
||
| /// <summary> | ||
| /// Verb Alias prefixes. | ||
| /// </summary> |
There was a problem hiding this comment.
Maybe these should be attributes, like:
public static class VerbsCommon
{
/// <summary>
/// Synonyms: Add to, append or attach.
/// </summary>
[AliasPrefix("a")]
public const string Add = "Add";
}There was a problem hiding this comment.
Looks good as common pattern.
Should we do this in the special case?
|
@PowerShell/powershell-committee reviewed this and we should change alias for |
| verb.Verb = field.Name; | ||
| verb.AliasPrefix = VerbAliasPrefixes.GetVerbAliasPrefix(field.Name); | ||
| verb.Group = groupName; | ||
| verb.Description = VerbDescriptions.Get(field.Name); |
There was a problem hiding this comment.
Above we use VerbAliasPrefixes.GetVerbAliasPrefix. I believe we should use the same pattern and use VerbDescriptions.GetVerbDescription.
|
@Tadas I edit the PR description for future documentation. |
|
@dantraMSFT Please re-review |
dantraMSFT
left a comment
There was a problem hiding this comment.
I suggest you remove the VerbDescription part of the resource name in VerbDescriptionStrings.resx and avoid the string allocation in VerbDescriptions.GetVerbDescription (verb + "VerbDescription"). By definition, there should not be a name collision so the allocation is unnecessary.
| } | ||
| } | ||
|
|
||
| It "Should have descriptions for all verbs" { |
There was a problem hiding this comment.
These tests are going to be a pain to diagnose when they fail.
I think it's work taking the time to emit the missing parts instead of simply comparing the counts.
For this test, build a list of verbs that don't have a description, join the result set into a string and validate it is null or empty to output the list of verbs that are missing descriptions. I would use the same pattern with $verbsWithPrefix.
For the last test; you'll want to output the verbs that have the same alias prefix.
An alternative would be to leave the tests as is, and create a helper function that outputs the exceptions. Add a note to the test to describe how to use the function.
There was a problem hiding this comment.
I'd prefer do this in place without a helper function
|
@dantraMSFT can you review again? |
|
LGTM! |
|
@Tadas Thanks for your contribution! Welcome with new ones! |
Fixes #4732 - VerbInfo should have a Description member
Fixes #4372 - Get-Verb should list alias prefixes too (extend System.Management.Automation.VerbInfo)
Summary
Added
VerbDescriptionsandVerbAliasPrefixesstatic classes with description and alias strings. Not actually sure if this is the best way to store the descriptions.To keep the descriptions short I only took the first sentence from https://msdn.microsoft.com/en-us/library/ms714428(v=vs.85).aspx "Action" field. Aliases come from the same page
Need document approved prefixes for some new verbs: