-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Get-Verb: add verb descriptions and alias prefixes #4746
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Descriptions needs to be in a resx file so they can be localized.
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.
Should it be internal?
|
|
||
| /// <summary> | ||
| /// "Build" verb alias prefix | ||
| /// </summary> |
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For "all verbs" we should count.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good as common pattern.
Should we do this in the special case?
|
@PowerShell/powershell-committee reviewed this and we should change alias for |
iSazonov
left a comment
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.
Leave a comment
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: