@@ -40,6 +40,14 @@ param(
40
40
$NEW_LINE = " `r`n " ;
41
41
. " $PSScriptRoot \StringProcessingHelper.ps1" ;
42
42
43
+ $CLI_HELP_MSG = " There are two sets of commands:\r\n" `
44
+ + " 1) function commands that are used to manage Azure resources in the cloud, and \r\n" `
45
+ + " 2) parameter commands that generate & edit input files for the other set of commands.\r\n" `
46
+ + " For example, \'vmss get/list/stop\' are the function commands that call get, list and stop operations of \r\n" `
47
+ + " virtual machine scale set, whereas \'vmss create-or-update-parameters * generate/set/remove/add\' commands \r\n" `
48
+ + " are used to configure the input parameter file. The \'vmss create-or-update\' command takes a parameter \r\n" `
49
+ + " file as for the VM scale set configuration, and creates it online." ;
50
+
43
51
function Get-ParameterCommandCategoryDescription
44
52
{
45
53
param
@@ -91,10 +99,11 @@ function Generate-CliParameterCommandImpl
91
99
{
92
100
[string ]$nodeName = Get-CliNormalizedName $parentNode.Name.Trim ();
93
101
[string ]$pathName = $nodeName ;
94
- if ($pathName.ToLower ().StartsWith(' ip' ))
95
- {
96
- $pathName = ' iP' + $pathName.Substring (2 );
97
- }
102
+ # Skip this for AutoRest, as the parameter names are always matched.
103
+ # if ($pathName.ToLower().StartsWith('ip'))
104
+ # {
105
+ # $pathName = 'iP' + $pathName.Substring(2);
106
+ # }
98
107
99
108
if ($parentNode.Parent -ne $null )
100
109
{
@@ -147,10 +156,13 @@ function Generate-CliParameterCommandImpl
147
156
}
148
157
else
149
158
{
150
- $sampleJsonText = " {\r\n ...\r\n" ;
151
- $sampleJsonText += " `" " + (Get-CliNormalizedName $TreeNode.Name ) + " `" : " ;
152
- $sampleJsonText += ($paramObjText.Replace (" `r`n " , " \r\n " )) + " \r\n" ;
153
- $sampleJsonText += " ...\r\n}\r\n" ;
159
+ $padding = " " ;
160
+ $sampleJsonText = $padding + " {\r\n" ;
161
+ $sampleJsonText += $padding + " ...\r\n" ;
162
+ $sampleJsonText += $padding + " `" " + (Get-CliNormalizedName $TreeNode.Name ) + " `" : " ;
163
+ $sampleJsonText += ($paramObjText.Replace (" `r`n " , " \r\n" + $padding + " " )) + " \r\n" ;
164
+ $sampleJsonText += $padding + " ...\r\n" ;
165
+ $sampleJsonText += $padding + " }\r\n" ;
154
166
}
155
167
156
168
if ($TreeNode.Properties.Count -gt 0 -or ($TreeNode.IsListItem ))
@@ -167,7 +179,7 @@ function Generate-CliParameterCommandImpl
167
179
$code += " var ${params_generate_category_var_name} = ${params_category_var_name} .category('${cli_method_option_name} ')" + $NEW_LINE ;
168
180
$code += " .description(`$ ('" + (Get-ParameterCommandCategoryDescription $cli_op_description $params_category_name $cli_method_option_name ) + " '));" + $NEW_LINE ;
169
181
$code += " ${params_generate_category_var_name} .command('${params_generate_category_name} ')" + $NEW_LINE ;
170
- $code += " .description(`$ ('Set ${cli_method_option_name} in ${params_category_name} string or files, e.g. \r\n${sampleJsonText} '))" + $NEW_LINE ;
182
+ $code += " .description(`$ ('Set ${cli_method_option_name} in ${params_category_name} string or files, e.g. \r\n${sampleJsonText} \r\n " + $CLI_HELP_MSG + " '))" + $NEW_LINE ;
171
183
$code += " .usage('[options]')" + $NEW_LINE ;
172
184
$code += " .option('--parameter-file <parameter-file>', `$ ('The parameter file path.'))" + $NEW_LINE ;
173
185
@@ -244,6 +256,12 @@ function Generate-CliParameterCommandImpl
244
256
$code += " if (options.parse && options.${paramName} ) {" + $NEW_LINE ;
245
257
$code += " options.${paramName} = JSON.parse(options.${paramName} );" + $NEW_LINE ;
246
258
$code += " }" + $NEW_LINE ;
259
+
260
+ if ($propertyItem [" IsPrimitive" ])
261
+ {
262
+ $code += " options.${paramName} = JSON.parse(options.${paramName} );" + $NEW_LINE ;
263
+ }
264
+
247
265
$code += " jsonpatch.apply(${cli_param_name} Obj, [{op: options.operation, path: paramPath, value: options.${paramName} }]);" + $NEW_LINE ;
248
266
$code += " }" + $NEW_LINE ;
249
267
}
@@ -274,7 +292,7 @@ function Generate-CliParameterCommandImpl
274
292
$code += " var ${params_generate_category_var_name} = ${params_category_var_name} .category('${cli_method_option_name} ')" + $NEW_LINE ;
275
293
$code += " .description(`$ ('" + (Get-ParameterCommandCategoryDescription $cli_op_description $params_category_name $cli_method_option_name ) + " '));" + $NEW_LINE ;
276
294
$code += " ${params_generate_category_var_name} .command('${params_generate_category_name} ')" + $NEW_LINE ;
277
- $code += " .description(`$ ('Remove ${cli_method_option_name} in ${params_category_name} string or files, e.g. \r\n${sampleJsonText} '))" + $NEW_LINE ;
295
+ $code += " .description(`$ ('Remove ${cli_method_option_name} in ${params_category_name} string or files, e.g. \r\n${sampleJsonText} \r\n " + $CLI_HELP_MSG + " '))" + $NEW_LINE ;
278
296
$code += " .usage('[options]')" + $NEW_LINE ;
279
297
$code += " .option('--parameter-file <parameter-file>', `$ ('The parameter file path.'))" + $NEW_LINE ;
280
298
@@ -364,7 +382,7 @@ function Generate-CliParameterCommandImpl
364
382
$code += " var ${params_generate_category_var_name} = ${params_category_var_name} .category('${cli_method_option_name} ')" + $NEW_LINE ;
365
383
$code += " .description(`$ ('" + (Get-ParameterCommandCategoryDescription $cli_op_description $params_category_name $cli_method_option_name ) + " '));" + $NEW_LINE ;
366
384
$code += " ${params_generate_category_var_name} .command('${params_generate_category_name} ')" + $NEW_LINE ;
367
- $code += " .description(`$ ('Add ${cli_method_option_name} in ${params_category_name} string or files, e.g. \r\n${sampleJsonText} '))" + $NEW_LINE ;
385
+ $code += " .description(`$ ('Add ${cli_method_option_name} in ${params_category_name} string or files, e.g. \r\n${sampleJsonText} \r\n " + $CLI_HELP_MSG + " '))" + $NEW_LINE ;
368
386
$code += " .usage('[options]')" + $NEW_LINE ;
369
387
$code += " .option('--parameter-file <parameter-file>', `$ ('The parameter file path.'))" + $NEW_LINE ;
370
388
$code += " .option('--key <key>', `$ ('The JSON key.'))" + $NEW_LINE ;
@@ -422,6 +440,12 @@ function Generate-CliParameterCommandImpl
422
440
$code += " if (options.parse && options.${paramName} ) {" + $NEW_LINE ;
423
441
$code += " options.${paramName} = JSON.parse(options.${paramName} );" + $NEW_LINE ;
424
442
$code += " }" + $NEW_LINE ;
443
+
444
+ if ($propertyItem [" IsPrimitive" ])
445
+ {
446
+ $code += " options.${paramName} = JSON.parse(options.${paramName} );" + $NEW_LINE ;
447
+ }
448
+
425
449
$code += " jsonpatch.apply(${cli_param_name} Obj, [{op: options.operation, path: paramPath, value: options.${paramName} }]);" + $NEW_LINE ;
426
450
$code += " }" + $NEW_LINE ;
427
451
}
0 commit comments