Skip to content

Get-Verb: add verb descriptions and alias prefixes - #4746

Merged
Mike Richmond (mirichmo) merged 15 commits into
PowerShell:masterfrom
Tadas:add-GetVerb-descriptions
Oct 12, 2017
Merged

Mike Richmond (mirichmo) merged 15 commits into
PowerShell:masterfrom
Tadas:add-GetVerb-descriptions

Conversation

@Tadas

@Tadas Tadas Medišauskas (Tadas) commented Sep 3, 2017 •

Copy link
Copy Markdown
Contributor

Fixes #4732 - VerbInfo should have a Description member
Fixes #4372 - Get-Verb should list alias prefixes too (extend System.Management.Automation.VerbInfo)

Summary

Added VerbDescriptions and VerbAliasPrefixes static 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:

  • Optimize - om
  • Resize - rz
  • Build - bd
  • Deploy - dp
  • Complete - cmp

@iSazonov

Copy link
Copy Markdown
Collaborator

Tadas Medišauskas (@Tadas) Thanks for your contribution!

Jason Shirk (@lzybkr) Could you please comment. Currently we use reflection and dynamically re-create verbinfo objects in Get-Verb cmdlet and also use reflection and build s_validVerbs and s_recommendedAlternateVerbs in Verbs.cs - perhaps the time has come to optimize performance of the code? Can we use someting like we use in Types_Ps1Xml.cs?


/// <summary>
/// Verb descriptions.
/// </summary>

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator

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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hemant Mahawar (@HemantMahawar) should probably be defining a prefix for the verbs which have none: Build, Deploy, Optimize, and Resize.

@HemantMahawar Hemant Mahawar (HemantMahawar) Sep 8, 2017 •

Copy link
Copy Markdown
Contributor

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 Joey Aiello (@joeyaiello)

@lzybkr

Copy link
Copy Markdown
Contributor

Tadas Medišauskas (@Tadas) Ilya (@iSazonov) - we don't need a cache for these new properties and reflection is fine - Get-Verb isn't important for performance.

s_recommendedAlternateVerbs should probably be Lazy - it shouldn't be normal to need it.

s_validVerbs could avoid reflection, but use reflection in debug builds to ensure that nothing was missed, but it never showed up in profiles during startup, so the difference might not be measurable.

VerbInfo verb = new VerbInfo();
verb.Verb = field.Name;

FieldInfo aliasField = typeof(VerbAliasPrefixes).GetField(field.Name);

Copy link
Copy Markdown
Contributor

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);

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Contributor Author

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?

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator

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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe GetVerbAliasPrefix ?

@Tadas

Copy link
Copy Markdown
Contributor Author

I've just noticed that Copy and Complete verbs have the same alias "cp". Should those be unique?

@Tadas

Copy link
Copy Markdown
Contributor Author

Hemant Mahawar (@HemantMahawar) Joey Aiello (@joeyaiello) what do you think of the duplicate verb prefixes for Complete and Copy?


/// <summary>
/// Verb Alias prefixes.
/// </summary>

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Collaborator

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?

@SteveL-MSFT Steve Lee (SteveL-MSFT) added Review - Committee The PR/Issue needs a review from the PowerShell Committee Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Sep 18, 2017
@SteveL-MSFT

Copy link
Copy Markdown
Member

@PowerShell/powershell-committee reviewed this and we should change alias for Complete to cmp

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

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);

Copy link
Copy Markdown
Collaborator

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.

@iSazonov Ilya (iSazonov) added the Documentation Needed in this repo Documentation is needed in this repo label Sep 26, 2017
@iSazonov

Copy link
Copy Markdown
Collaborator

Tadas Medišauskas (@Tadas) I edit the PR description for future documentation.

@mirichmo

Copy link
Copy Markdown
Member

Dan Travison (@dantraMSFT) Please re-review

@dantraMSFT Dan Travison (dantraMSFT) left a comment

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator

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

@SteveL-MSFT

Copy link
Copy Markdown
Member

Dan Travison (@dantraMSFT) can you review again?

@dantraMSFT

Copy link
Copy Markdown
Contributor

LGTM!

@iSazonov

Copy link
Copy Markdown
Collaborator

Tadas Medišauskas (@Tadas) Thanks for your contribution! Welcome with new ones!

@mirichmo
Mike Richmond (mirichmo) merged commit 844bf11 into PowerShell:master Oct 12, 2017
@Tadas
Tadas Medišauskas (Tadas) deleted the add-GetVerb-descriptions branch October 23, 2017 06:43
@joeyaiello Joey Aiello (joeyaiello) removed Documentation Needed in this repo Documentation is needed in this repo labels Oct 15, 2018
Christopher Yeleighton (yecril71pl) added a commit to yecril71pl/PowerShell that referenced this pull request Jul 24, 2020
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
* Get-Verb: add descriptions and prefixes

* Add description and alias prefix tests

* Make the new classes internal

* Convert alias prefix to static method

* Move verb descriptions to a resource file

* Shorten function name

* Shorten alias prefix function name

* Change tests to look at counts

* Add uniqueness test

* Add missing alias prefixes

* Fix name collision

* Change alias prefix for Compare

* Rename method

* Remove unnecessary string allocation

* Make tests easier to diagnose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VerbInfo should have a Description member Get-Verb should list alias prefixes too (extend System.Management.Automation.VerbInfo)

10 participants