-
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
Changes from all commits
7708bb5
37f8700
fd9ca3a
e38ff70
69516a3
67e5b30
ef13db6
74df39c
809d05f
7879aa2
64d55f6
2ef14aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
using Microsoft.Azure.Commands.Common.Strategies; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
|
@@ -28,6 +31,11 @@ public static async Task<TModel> RunAsync<TModel>( | |
var engine = new SdkEngine(client.SubscriptionId); | ||
var target = config.GetTargetState(current, engine, parameters.Location); | ||
|
||
foreach (var p in asyncCmdlet.Parameters) | ||
{ | ||
asyncCmdlet.WriteVerbose(p.Key + " = " + ToPowerShellString(p.Value)); | ||
} | ||
|
||
// apply target state | ||
var newState = await config.UpdateStateAsync( | ||
client, | ||
|
@@ -38,5 +46,24 @@ public static async Task<TModel> RunAsync<TModel>( | |
|
||
return newState.Get(config) ?? current.Get(config); | ||
} | ||
|
||
static string ToPowerShellString(object value) | ||
{ | ||
if (value == null) | ||
{ | ||
return "$null"; | ||
} | ||
var s = value as string; | ||
if (s != null) | ||
{ | ||
return "\"" + s + "\""; | ||
} | ||
var e = value as IEnumerable; | ||
if (e != null) | ||
{ | ||
return string.Join(",", e.Cast<object>().Select(ToPowerShellString)); | ||
} | ||
return value.ToString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes, if we don't know the type we use |
||
} | ||
} | ||
} |
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()
andPropertyInfo.GetCustomAttributes()
never returnsnull
.