Skip to content

Conversation

@Tadas
Copy link
Contributor

@Tadas Tadas commented Sep 3, 2017

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
Collaborator

iSazonov commented Sep 4, 2017

@Tadas Thanks for your contribution!

@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
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
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
Contributor

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.

Copy link
Contributor

@HemantMahawar HemantMahawar Sep 8, 2017

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

@lzybkr
Copy link
Contributor

lzybkr commented Sep 4, 2017

@Tadas @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
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
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
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
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
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
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
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
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
Contributor Author

Tadas commented Sep 8, 2017

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

@Tadas
Copy link
Contributor Author

Tadas commented Sep 17, 2017

@HemantMahawar @joeyaiello what do you think of the duplicate verb prefixes for Complete and Copy?


/// <summary>
/// Verb Alias prefixes.
/// </summary>
Copy link
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
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 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
Member

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

Copy link
Collaborator

@iSazonov iSazonov left a 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);
Copy link
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 iSazonov added the Documentation Needed in this repo Documentation is needed in this repo label Sep 26, 2017
@iSazonov
Copy link
Collaborator

@Tadas I edit the PR description for future documentation.

@mirichmo
Copy link
Member

@dantraMSFT Please re-review

Copy link
Contributor

@dantraMSFT dantraMSFT left a 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" {
Copy link
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
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
Member

@dantraMSFT can you review again?

@dantraMSFT
Copy link
Contributor

LGTM!

@iSazonov
Copy link
Collaborator

@Tadas Thanks for your contribution! Welcome with new ones!

@mirichmo mirichmo merged commit 844bf11 into PowerShell:master Oct 12, 2017
@Tadas Tadas deleted the add-GetVerb-descriptions branch October 23, 2017 06:43
@joeyaiello joeyaiello removed Documentation Needed in this repo Documentation is needed in this repo labels Oct 15, 2018
yecril71pl added a commit to yecril71pl/PowerShell that referenced this pull request Jul 24, 2020
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