-
Notifications
You must be signed in to change notification settings - Fork 4k
Add ResourceGroup to DefaultParameterValues #4911
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
@azuresdkci test this please |
tools/UpdateModules.ps1
Outdated
if ($AddDefaultParameters) | ||
{ | ||
$nestedModules = $ModuleMetadata.NestedModules | ||
$AllCmdlets = @() |
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.
It feels like we should factor this out into its own 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.
done
tools/UpdateModules.ps1
Outdated
} | ||
|
||
$FilteredCommands = @() | ||
$AllCmdlets | ForEach-Object { |
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 also feels like it could be in it's own function that returned a predicate, so that this function would basically be
$nestedModules | Get-CmdletType | Where-Object {Test-RequiredParameter -Cmdlet $_ -ParameterName "ResourceGroup"}
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
{ | ||
$rgParameter = $Cmdlet.GetProperties() | Where-Object {$_.Name -eq "ResourceGroupName"} | ||
if ($rgParameter -ne $null) { | ||
$parameterSets = $rgParameter.CustomAttributes | Where-Object {$_.AttributeType.Name -eq "ParameterAttribute"} |
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 think this variable name is a bit confusing - I thought this was an enumeration of parameter sets, but it is really just anenumeration of parameter attributes. Renaming this to '$parameters' or '$parameterAttributes' would make the code a bit easier to read, I think.
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
return "`$module = Get-Module $ModuleName ` | ||
if (`$module -ne `$null -and `$module.Version.ToString().CompareTo(`"$MinimumVersion`") -lt 0) ` | ||
{ ` | ||
Write-Warning `"A later version of $ModuleName was found to be imported already. Please see <link> for more details.`" ` |
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 think thsi is a bit out oif date with the latest in Cormac's PR. Please pull the latest
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
} | ||
|
||
else { | ||
return "@()" |
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.
Are we return a string representing the code for an array?
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, when put into the template it will be interpreted as an array.
tools/UpdateModules.ps1
Outdated
} | ||
} | ||
|
||
function Test-RequiredParameter |
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.
Perhaps this should be Test-CmdletRequiredParameter
and the parameter name should likely be a parameter.
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
$FilteredCommands | ForEach-Object { | ||
$global:PSDefaultParameterValues.Add($_, | ||
{ | ||
$context = Get-AzureRmContext |
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 happens if there is no context (the user hasn't logged in yet)? Wnat to make sure that we are not pushing errors into the Error stream.
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.
Added a null check
packaging job here: https://azuresdkci.westus2.cloudapp.azure.com/view/PowerShell/job/posh-pack/19/ |
Description
Add default resource group to every cmdlet that has ResourceGroupName mandatory for every parameter #3808. Based off of changes in #4734.
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