-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix Argument Completers #4945
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
Fix Argument Completers #4945
Conversation
tools/AzureRM.Example.psm1
Outdated
$ResourceGroupCommands = %RGCCOMMANDS% | ||
|
||
$CommonAssembly = [Reflection.Assembly]::LoadFrom('.\Microsoft.Azure.Commands.ResourceManager.Common.dll') |
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.
Why do we need to define $CommonAssembly? This assembly should be loaded in the ImportedDependencies above.
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.
Done
tools/UpdateModules.ps1
Outdated
$resourceGroupCompleterCommands = Find-CompleterAttribute -CompleterName "ResourceGroupCompleterAttribute" -ModuleMetadata $ModuleMetadata -ModulePath $ModulePath -isRMModule $isRMModule | ||
$template = $template -replace "%RGCCOMMANDS%", $resourceGroupCompleterCommands | ||
|
||
$locationCompleterCommands = Find-CompleterAttribute -CompleterName "LocationCompleterAttribute" -ModuleMetadata $ModuleMetadata -ModulePath $ModulePath -isRMModule $isRMModule |
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.
what is the result if the list is empty?
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.
if the list is empty, an empty list will be inserted into the template and no completers will be registered in the foreach loop,
tools/UpdateModules.ps1
Outdated
@@ -122,22 +191,22 @@ $templateLocation = "$PSScriptRoot\AzureRM.Example.psm1" | |||
if (($scope -eq 'All') -or $publishToLocal ) { | |||
# If we publish 'All' or to local folder, publish AzureRM.Profile first, becasue it is the common dependency | |||
Write-Host "Updating profile module" | |||
Create-ModulePsm1 -ModulePath "$resourceManagerRootFolder\AzureRM.Profile" -TemplatePath $templateLocation | |||
Create-ModulePsm1 -ModulePath "$resourceManagerRootFolder\AzureRM.Profile" -TemplatePath $templateLocation $true |
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.
this last parameter should be a named parameter, so there is some indication of what this is doing.
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.
Done
tools/UpdateModules.ps1
Outdated
if ($completerAttribute -ne $null) { | ||
$constructedCommands += "@('" + $currentCmdlet.GetCustomAttributes("System.Management.Automation.CmdletAttribute").VerbName + "-" + $currentCmdlet.GetCustomAttributes("System.Management.Automation.CmdletAttribute").NounName + "', " | ||
$constructedCommands += "'" + $_.Name + "', " | ||
if ($completerAttribute.ConstructorArguments.Count -eq 0) |
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.
this would be simplified if you store the cmdletattribute in a varaible:
$AtrributeTypeName="System.Management.Automation.CmdletAttribute"
$cmdletAttribute = $currentCmdlet.GetCustomAttributes($attributeTypeName)
It also seems like the result should be a list of hashtables @{CmdletName="<name>"; CmdletType="<typeName>"}
this will make any code that uses this list a bit easier to read.
Finally, I think we should add some methods to the attribute itself to generate the list of constructor argument values, i.e. $completerAttribute.GetConstructorArgumentList() .
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 problem with the hashtable is that we actual need three values: the cmdlet name, the parameter name, and the attribute arguments (for the location completer). I could make a hashtable of hashtables, but I think that the list of lists might be easier to read in this case. If you would like me to change it let me know.
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 wrote the code adding a method for generating the list of constructor arguments, but it actually ended up being more convoluted because I had to create a new LocationCompleterAttribute object and convert the list of strings from c# to powershell. I'll leave this how it is for now, but let me know if you would rather creating a new method.
tools/UpdateModules.ps1
Outdated
@@ -26,7 +26,8 @@ function Create-ModulePsm1 | |||
[CmdletBinding()] | |||
param( | |||
[string]$ModulePath, | |||
[string]$TemplatePath | |||
[string]$TemplatePath, | |||
[bool]$isRMModule |
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.
Follow the conventiosn with capital i
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.
done
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 like this is still lower case 'i'
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.
Yikes. Fixed.
{ | ||
} | ||
|
||
public virtual string[] GetCompleterValues() |
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 can make this abstract, so that no impementation is necessary (If the class is abstract, it also cannot be created).
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.
done
tools/UpdateModules.ps1
Outdated
@@ -26,7 +26,8 @@ function Create-ModulePsm1 | |||
[CmdletBinding()] | |||
param( | |||
[string]$ModulePath, | |||
[string]$TemplatePath | |||
[string]$TemplatePath, | |||
[bool]$isRMModule |
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 like this is still lower case 'i'
@azuresdkci test this please |
on demand run here: https://azuresdkci.westus2.cloudapp.azure.com/view/PowerShell/job/powershell-demand/186/ Successful sign job here: https://azuresdkci.westus2.cloudapp.azure.com/view/PowerShell/job/powershell-sign/16/ |
@maddieclayton I've added the posh-pack and release builds below as well - as long as the packaging job produces usable debug build, and the release job passes (does not need to produce a working build), then we are good to merge this. Excellent work! packaging run: https://azuresdkci.westus2.cloudapp.azure.com/view/PowerShell/job/posh-pack/23/ |
posh-release run here: https://azuresdkci.westus2.cloudapp.azure.com/job/posh-release/2/ |
Description
#4910
Add script to psm1 file that will register Location/ResourceGroup argument completers.
This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.
General Guidelines
Testing Guidelines
Cmdlet Signature Guidelines
ShouldProcess
and haveSupportShouldProcess=true
specified in the cmdlet attribute. You can find more information onShouldProcess
here.OutputType
attribute if any output is produced - if the cmdlet produces no output, it should implement aPassThru
parameter.Cmdlet Parameter Guidelines