@@ -162,6 +162,33 @@ function Get-NormalizedName
162
162
return $outputName ;
163
163
}
164
164
165
+ function Get-UnnormalizedName
166
+ {
167
+ # Sample: 'VMName' to 'vmName', 'VirtualMachine' => 'virtualMachine', 'ResourceGroup' => 'resourceGroup', etc.
168
+ param (
169
+ [Parameter (Mandatory = $True )]
170
+ [string ]$inputName
171
+ )
172
+
173
+ if ([string ]::IsNullOrEmpty($inputName ))
174
+ {
175
+ return $inputName ;
176
+ }
177
+
178
+ if ($inputName.StartsWith (' VM' ))
179
+ {
180
+ $outputName = ' vm' + $inputName.Substring (2 );
181
+ }
182
+ else
183
+ {
184
+ [char ]$firstChar = $inputName [0 ];
185
+ $firstChar = [System.Char ]::ToLower($firstChar );
186
+ $outputName = $firstChar + $inputName.Substring (1 );
187
+ }
188
+
189
+ return $outputName ;
190
+ }
191
+
165
192
function Get-NormalizedTypeName
166
193
{
167
194
param (
@@ -1289,6 +1316,7 @@ function Write-OperationCmdletFile
1289
1316
[System.Collections.ArrayList ]$invoke_param_names = @ ();
1290
1317
[System.Collections.ArrayList ]$invoke_local_param_names = @ ();
1291
1318
[System.Collections.ArrayList ]$create_local_param_names = @ ();
1319
+ [System.Collections.ArrayList ]$cli_command_param_names = @ ();
1292
1320
$position_index = 1 ;
1293
1321
foreach ($pt in $params )
1294
1322
{
@@ -1537,6 +1565,49 @@ ${cmdlet_partial_class_code}
1537
1565
Write-Output $dynamic_param_source_template ;
1538
1566
Write-Output $invoke_cmdlt_source_template ;
1539
1567
Write-Output $parameter_cmdlt_source_template ;
1568
+
1569
+ # CLI Code
1570
+ $cli_op_name = Get-UnnormalizedName $opShortName ;
1571
+ $cli_method_name = Get-UnnormalizedName $methodName ;
1572
+
1573
+ $cli_op_code_content = " //" + $opShortName + " ." + $methodName + $new_line_str ;
1574
+ $component_name = ' compute' ;
1575
+ $cli_op_code_content += " var $opShortName = compute.category('$cli_op_name ').description(`$ ('Commands for Azure Compute'));" ;
1576
+
1577
+ $cli_op_code_content += " ${opShortName} .command('${methodName} ')" + $new_line_str ;
1578
+ $cli_op_code_content += " .description(`$ ('${opShortName} ${methodName} '))" + $new_line_str ;
1579
+ $cli_op_code_content += " .usage('[options]')" + $new_line_str ;
1580
+ for ($index = 0 ; $index -lt $param_names.Count ; $index ++ )
1581
+ {
1582
+ $cli_param_name = $param_names [$index ];
1583
+ $cli_op_code_content += " .option('--${cli_param_name} <${cli_param_name} >', `$ ('${cli_param_name} '))" + $new_line_str ;
1584
+ }
1585
+ $cli_op_code_content += " .option('-s, --subscription <subscription>', `$ ('the subscription identifier'))" + $new_line_str ;
1586
+ $cli_op_code_content += " .execute(function ("
1587
+ for ($index = 0 ; $index -lt $param_names.Count ; $index ++ )
1588
+ {
1589
+ if ($index -gt 0 ) { $cli_op_code_content += " , " ; }
1590
+ $cli_param_name = $param_names [$index ];
1591
+ $cli_op_code_content += " $cli_param_name " ;
1592
+ }
1593
+ $cli_op_code_content += " , options, _) {" + $new_line_str ;
1594
+ $cli_op_code_content += " var subscription = profile.current.getSubscription(options.subscription);" + $new_line_str ;
1595
+ $cli_op_code_content += " var computeManagementClient = utils.createComputeResourceProviderClient(subscription);" + $new_line_str ;
1596
+ $cli_op_code_content += " var result = computeManagementClient.${cli_op_name} s.${cli_method_name} (" ;
1597
+ for ($index = 0 ; $index -lt $param_names.Count ; $index ++ )
1598
+ {
1599
+ if ($index -gt 0 ) { $cli_op_code_content += " , " ; }
1600
+ $cli_param_name = $param_names [$index ];
1601
+ $cli_op_code_content += " $cli_param_name " ;
1602
+ }
1603
+ $cli_op_code_content += " , _);" + $new_line_str ;
1604
+ $cli_op_code_content += " cli.output.json(result);" + $new_line_str ;
1605
+ $cli_op_code_content += " });" + $new_line_str ;
1606
+
1607
+
1608
+
1609
+
1610
+ Write-Output $cli_op_code_content ;
1540
1611
}
1541
1612
1542
1613
# Sample: VirtualMachineCreateParameters
@@ -1784,6 +1855,23 @@ ${cmdlet_generated_code}
1784
1855
$st = Set-Content - Path $file_full_path - Value $cmdlt_source_template - Force;
1785
1856
}
1786
1857
1858
+
1859
+ # Sample: NewAzureVirtualMachineCreateParameters.cs
1860
+ function Write-CLICommandFile
1861
+ {
1862
+ param (
1863
+ [Parameter (Mandatory = $True )]
1864
+ [string ]$fileOutputFolder ,
1865
+
1866
+ [Parameter (Mandatory = $True )]
1867
+ $commandCodeLines
1868
+ )
1869
+
1870
+ $fileFullPath = $fileOutputFolder + ' /' + ' cli.js' ;
1871
+
1872
+ $st = Set-Content - Path $fileFullPath - Value $commandCodeLines - Force;
1873
+ }
1874
+
1787
1875
# Code Generation Main Run
1788
1876
$outFolder += ' /Generated' ;
1789
1877
@@ -1839,6 +1927,40 @@ else
1839
1927
$dynamic_param_method_code = @ ();
1840
1928
$invoke_cmdlet_method_code = @ ();
1841
1929
$parameter_cmdlet_method_code = @ ();
1930
+ $cli_command_method_code =
1931
+ @"
1932
+ /**
1933
+ * Copyright (c) Microsoft. All rights reserved.
1934
+ *
1935
+ * Licensed under the Apache License, Version 2.0 (the "License");
1936
+ * you may not use this file except in compliance with the License.
1937
+ * You may obtain a copy of the License at
1938
+ * http://www.apache.org/licenses/LICENSE-2.0
1939
+ *
1940
+ * Unless required by applicable law or agreed to in writing, software
1941
+ * distributed under the License is distributed on an "AS IS" BASIS,
1942
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1943
+ * See the License for the specific language governing permissions and
1944
+ * limitations under the License.
1945
+ */
1946
+
1947
+ 'use strict';
1948
+
1949
+ var __ = require('underscore');
1950
+ var util = require('util');
1951
+
1952
+ var profile = require('../../../util/profile');
1953
+ var utils = require('../../../util/utils');
1954
+
1955
+ var $ = utils.getLocaleString;
1956
+
1957
+ exports.init = function (cli) {
1958
+
1959
+ var compute = cli.category('compute')
1960
+ .description(`$ ('Commands for Azure Compute'));
1961
+
1962
+
1963
+ "@ ;
1842
1964
1843
1965
# Write Operation Cmdlet Files
1844
1966
foreach ($ft in $filtered_types )
@@ -1869,9 +1991,10 @@ else
1869
1991
$outputs = Write-OperationCmdletFile $opOutFolder $opShortName $mt $invoke_cmdlet_class_name $parameter_cmdlet_class_name ;
1870
1992
if ($outputs.Count -ne $null )
1871
1993
{
1872
- $dynamic_param_method_code += $outputs [-3 ];
1873
- $invoke_cmdlet_method_code += $outputs [-2 ];
1874
- $parameter_cmdlet_method_code += $outputs [-1 ];
1994
+ $dynamic_param_method_code += $outputs [-4 ];
1995
+ $invoke_cmdlet_method_code += $outputs [-3 ];
1996
+ $parameter_cmdlet_method_code += $outputs [-2 ];
1997
+ $cli_command_method_code += $outputs [-1 ];
1875
1998
}
1876
1999
1877
2000
[System.Reflection.ParameterInfo ]$parameter_type_info = (Get-MethodComplexParameter $mt $client_library_namespace );
@@ -1909,6 +2032,13 @@ else
1909
2032
Write-NewParameterObjectCmdletFile $new_object_cmdlet_file_name $new_object_cmdlet_class_name $auto_base_cmdlet_name $clientClassType $filtered_types $parameter_cmdlet_method_code ;
1910
2033
}
1911
2034
2035
+ # CLI
2036
+ $cli_command_method_code += $new_line_str + " };" ;
2037
+ if ($cmdletFlavor -eq ' CLI' )
2038
+ {
2039
+ Write-CLICommandFile $outFolder $cli_command_method_code ;
2040
+ }
2041
+
1912
2042
Write-Output " =============================================" ;
1913
2043
Write-Output " Finished." ;
1914
2044
Write-Output " =============================================" ;
0 commit comments