-
Notifications
You must be signed in to change notification settings - Fork 4k
New-AzureRmVm/VMSS: verbose parameter output. #5933
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
return typeof(T) | ||
.GetProperties() | ||
.Where(p => p | ||
.GetCustomAttributes(false) |
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.
we should check for null here, what if there is a random class property that does not have any custom attributes... will the code here throw a null ptr exception?
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.
Type.GetProperties()
and PropertyInfo.GetCustomAttributes()
never returns null
.
.Where(p => p | ||
.GetCustomAttributes(false) | ||
.OfType<ParameterAttribute>() | ||
.Any(a => a.ParameterSetName == psName)) |
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 about parameters like : https://github.com/praries880/azure-powershell/blob/dependency_fix/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/GetAzureVMCommand.cs#L64
which do not have the property specified? what happens in this case?
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've a fix. I'm going to push it soon.
{ | ||
return string.Join(",", e.Cast<object>().Select(ToPowerShellString)); | ||
} | ||
return value.ToString(); |
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.
so for this, if the type of the parameter (specifically for custom defined classes) does not implement a ToString() this would just print out the object type instead of a string representation of the data in the object? Do we want to do this?
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, if we don't know the type we use object.ToString()
function. This's also default PowerShell behavior.
Want about adding unit tests for this scenario? |
@praries880 I'm going to introduce unit tests in #5972 where the code is used in a generic Strategy library. |
{ | ||
_Cmdlet = cmdlet; | ||
} | ||
|
||
public bool WhatIf |
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.
@sergey-shandar As we have discussed, this is an anti-pattern, we should not print additional information based on our own setting of WhatIf - WhatIf should be handled automaticsally by the PowerShell runtime. Additional information printed in WhatIf should use only ShouldProcess prompts.
Verbose output should simply be written to the verbose stream - we cna log such output to the Verbose or Debug streams, depending on the level of information (verbose versus debug/very verbose)
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.
@markcowl Good catch! I forgot to remove the property. Note: the property was not used anyway, so the behavior is still the same: the cmdlet doesn't relay on the WhatIf
parameter.
Description
#5650
Known issues:
IEnumerable
null
.ToString()
for everything elseChecklist
CONTRIBUTING.md
platyPS
module