From a3dfcb9644bc329df218469195ab42d033e709cb Mon Sep 17 00:00:00 2001 From: qiaozha Date: Thu, 23 Apr 2020 14:30:37 +0800 Subject: [PATCH 1/2] fix-issue-282-273 --- src/plugins/azgenerator/CodeModelAz.ts | 1 + .../azgenerator/TemplateAzureCliParams.ts | 32 ++++++++++++++++++- .../datafactory/configuration/readme.az.md | 10 ++++++ .../azext_datafactory/generated/_params.py | 12 +++---- .../generated/_params.py | 20 +++++++----- 5 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/plugins/azgenerator/CodeModelAz.ts b/src/plugins/azgenerator/CodeModelAz.ts index 77c7adacc..0ab0a50ec 100644 --- a/src/plugins/azgenerator/CodeModelAz.ts +++ b/src/plugins/azgenerator/CodeModelAz.ts @@ -71,6 +71,7 @@ export interface CodeModelAz CommandGroup: OperationGroup; CommandGroup_Name: string; CommandGroup_Help: string; + CommandGroup_DefaultName: string; SelectFirstCommand(): boolean; SelectNextCommand(): boolean; diff --git a/src/plugins/azgenerator/TemplateAzureCliParams.ts b/src/plugins/azgenerator/TemplateAzureCliParams.ts index 4755f343d..c364b02e5 100644 --- a/src/plugins/azgenerator/TemplateAzureCliParams.ts +++ b/src/plugins/azgenerator/TemplateAzureCliParams.ts @@ -7,7 +7,7 @@ import { CodeModelAz } from "./CodeModelAz" import { EscapeString, ToCamelCase, Capitalize, ToMultiLine } from "../../utils/helper"; import { SchemaType, Parameter } from "@azure-tools/codemodel"; import { HeaderGenerator } from "./Header"; -import { isNullOrUndefined } from "util"; +import { isNullOrUndefined, isArray } from "util"; let hasActions: boolean = false; @@ -171,8 +171,38 @@ function getCommandBody(model: CodeModelAz, needUpdate: boolean = false, needGen argument = " c.argument('" + parameterName + "'"; argument += ", options_list=['--" + parameterName.substr(0, parameterName.length - 1) + "']"; + } else if (parameterName.endsWith('name') && parameterName.replace(/_name|_/g, '') == model.CommandGroup_DefaultName.toLowerCase()) { + argument = " c.argument('" + parameterName + "'"; + argument += ", options_list=['--name', '-n']"; + } else if(!isNullOrUndefined(model.MethodParameter?.language?.['cli']?.['alias'])) { + argument = " c.argument('" + parameterName + "'"; + let alias = model.MethodParameter?.language?.['cli']?.['alias']; + let aliases: string[] = []; + if(typeof alias === "string") { + aliases.push(alias); + + } + if (isArray(alias)) { + aliases = alias; + } + if(aliases.length > 0) { + let alias_str = []; + for(let alias of aliases) { + alias = alias.replace(/'/g, ''); + if(alias.length == 1) { + alias = "'-" + alias + "'"; + } else if(alias.length > 1) { + alias = "'--" + alias + "'"; + } + alias_str.push(alias); + } + argument += ", options_list=[" + alias_str.join(', ') + "]"; + } + } + + if (model.MethodParameter_Type == SchemaType.Boolean) { hasBoolean = true; argument += ", arg_type=get_three_state_flag()"; diff --git a/src/test/scenarios/datafactory/configuration/readme.az.md b/src/test/scenarios/datafactory/configuration/readme.az.md index 33df587bb..9c02d8dda 100644 --- a/src/test/scenarios/datafactory/configuration/readme.az.md +++ b/src/test/scenarios/datafactory/configuration/readme.az.md @@ -16,4 +16,14 @@ directive: set: group: datafactory + +cli: + cli-directive: + # directive on operationGroup + - where: + parameter: factoryName + alias: + - name + - n + ``` diff --git a/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/_params.py b/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/_params.py index 6e750cba4..1e2517c31 100644 --- a/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/_params.py +++ b/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/_params.py @@ -31,13 +31,13 @@ def load_arguments(self, _): with self.argument_context('datafactory show') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('factory_name', help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.') c.argument('if_none_match', help='ETag of the factory entity. Should only be specified for get. If the ETag mat' 'ches the existing entity tag, or if * was provided, then no content will be returned.') with self.argument_context('datafactory create') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('factory_name', help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.') c.argument('if_match', help='ETag of the factory entity. Should only be specified for update, for which it shou' 'ld match existing entity or can be * for unconditional update.') c.argument('location', arg_type=get_location_type(self.cli_ctx), @@ -56,14 +56,14 @@ def load_arguments(self, _): with self.argument_context('datafactory update') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('factory_name', help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.') c.argument('tags', tags_type) c.argument('identity', action=AddIdentity, nargs='+', help='Managed service identity of the factory. Expect val' 'ue: KEY1=VALUE1 KEY2=VALUE2 ...') with self.argument_context('datafactory delete') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('factory_name', help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.') with self.argument_context('datafactory configure-factory-repo') as c: c.argument('location_id', help='The location identifier.') @@ -79,7 +79,7 @@ def load_arguments(self, _): with self.argument_context('datafactory get-data-plane-access') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('factory_name', help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.') c.argument('permissions', help='The string with permissions for Data Plane access. Currently only \'r\' is supp' 'orted which grants read only access.') c.argument('access_resource_path', help='The resource path to get access relative to factory. Currently only em' @@ -92,7 +92,7 @@ def load_arguments(self, _): with self.argument_context('datafactory get-git-hub-access-token') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('factory_name', help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.') c.argument('git_hub_access_code', help='GitHub access code.') c.argument('git_hub_client_id', help='GitHub application client ID.') c.argument('git_hub_access_token_base_url', help='GitHub access token base URL.') diff --git a/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/_params.py b/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/_params.py index 854009caa..d8475c9b0 100644 --- a/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/_params.py +++ b/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/_params.py @@ -38,11 +38,11 @@ def load_arguments(self, _): with self.argument_context('managed-network mn show') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('managed_network_name', help='The name of the Managed Network.') + c.argument('managed_network_name', options_list=['--name', '-n'], help='The name of the Managed Network.') with self.argument_context('managed-network mn create') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('managed_network_name', help='The name of the Managed Network.') + c.argument('managed_network_name', options_list=['--name', '-n'], help='The name of the Managed Network.') c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group) c.argument('tags', tags_type) @@ -51,19 +51,20 @@ def load_arguments(self, _): with self.argument_context('managed-network mn update') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('managed_network_name', help='The name of the Managed Network.') + c.argument('managed_network_name', options_list=['--name', '-n'], help='The name of the Managed Network.') c.argument('tags', tags_type) with self.argument_context('managed-network mn delete') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('managed_network_name', help='The name of the Managed Network.') + c.argument('managed_network_name', options_list=['--name', '-n'], help='The name of the Managed Network.') with self.argument_context('managed-network mn scope-assignment list') as c: c.argument('scope', help='The base resource of the scope assignment.') with self.argument_context('managed-network mn scope-assignment show') as c: c.argument('scope', help='The base resource of the scope assignment.') - c.argument('scope_assignment_name', help='The name of the scope assignment to get.') + c.argument('scope_assignment_name', options_list=['--name', '-n'], help='The name of the scope assignment to ge' + 't.') with self.argument_context('managed-network mn scope-assignment create') as c: c.argument('scope', help='The base resource of the scope assignment to create. The scope can be any REST resour' @@ -71,7 +72,8 @@ def load_arguments(self, _): 'ns/{subscription-id}/resourceGroups/{resource-group-name}\' for a resource group, and \'subscriptio' 'ns/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider}/{resource-t' 'ype}/{resource-name}\' for a resource.') - c.argument('scope_assignment_name', help='The name of the scope assignment to create.') + c.argument('scope_assignment_name', options_list=['--name', '-n'], help='The name of the scope assignment to cr' + 'eate.') c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group) c.argument('assigned_managed_network', help='The managed network ID with scope will be assigned to.') @@ -82,14 +84,16 @@ def load_arguments(self, _): 'ns/{subscription-id}/resourceGroups/{resource-group-name}\' for a resource group, and \'subscriptio' 'ns/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider}/{resource-t' 'ype}/{resource-name}\' for a resource.') - c.argument('scope_assignment_name', help='The name of the scope assignment to create.') + c.argument('scope_assignment_name', options_list=['--name', '-n'], help='The name of the scope assignment to cr' + 'eate.') c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group) c.argument('assigned_managed_network', help='The managed network ID with scope will be assigned to.') with self.argument_context('managed-network mn scope-assignment delete') as c: c.argument('scope', help='The scope of the scope assignment to delete.') - c.argument('scope_assignment_name', help='The name of the scope assignment to delete.') + c.argument('scope_assignment_name', options_list=['--name', '-n'], help='The name of the scope assignment to de' + 'lete.') with self.argument_context('managed-network mn group list') as c: c.argument('resource_group_name', resource_group_name_type) From 7d288b503fc23da7cd4963e5d4e4ab525b8f7228 Mon Sep 17 00:00:00 2001 From: qiaozha Date: Thu, 23 Apr 2020 15:16:00 +0800 Subject: [PATCH 2/2] fix issue 273 --- src/plugins/azgenerator/TemplateAzureCliSetupPy.ts | 14 +++++++++----- .../attestation/output/src/attestation/setup.py | 14 +++++++++----- .../datafactory/output/src/datafactory/setup.py | 14 +++++++++----- .../output/src/managed-network/setup.py | 14 +++++++++----- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/plugins/azgenerator/TemplateAzureCliSetupPy.ts b/src/plugins/azgenerator/TemplateAzureCliSetupPy.ts index bda95b1b9..a024f0fd7 100644 --- a/src/plugins/azgenerator/TemplateAzureCliSetupPy.ts +++ b/src/plugins/azgenerator/TemplateAzureCliSetupPy.ts @@ -19,9 +19,12 @@ export function GenerateAzureCliSetupPy(model: CodeModelAz) : string[] { output.push("from codecs import open"); output.push("from setuptools import setup, find_packages"); output.push(""); - output.push("# TODO: Confirm this is the right version number you want and it matches your"); output.push("# HISTORY.rst entry."); output.push("VERSION = '0.1.0'"); + output.push("try:"); + output.push(" from .manual.version import VERSION"); + output.push("except ImportError:"); + output.push(" pass"); output.push("") output.push("# The full list of classifiers is available at"); output.push("# https://pypi.python.org/pypi?%3Aaction=list_classifiers"); @@ -37,8 +40,11 @@ export function GenerateAzureCliSetupPy(model: CodeModelAz) : string[] { output.push(" 'License :: OSI Approved :: MIT License',"); output.push("]"); output.push(""); - output.push("# TODO: Add any additional SDK dependencies here"); output.push("DEPENDENCIES = []"); + output.push("try:"); + output.push(" from .manual.dependency import DEPENDENCIES"); + output.push("except ImportError:"); + output.push(" pass"); output.push(""); output.push("with open('README.md', 'r', encoding='utf-8') as f:"); output.push(" README = f.read()"); @@ -49,11 +55,9 @@ export function GenerateAzureCliSetupPy(model: CodeModelAz) : string[] { output.push(" name='" + model.Extension_NameUnderscored + "',"); output.push(" version=VERSION,"); output.push(" description='Microsoft Azure Command-Line Tools " + model.Extension_NameClass + " Extension',"); - output.push(" # TODO: Update author and email, if applicable"); output.push(" author='Microsoft Corporation',"); output.push(" author_email='azpycli@microsoft.com',"); - output.push(" # TODO: consider pointing directly to your source code instead of the generic repo"); - output.push(" url='https://github.com/Azure/azure-cli-extensions',"); + output.push(" url='https://github.com/Azure/azure-cli-extensions/tree/master/src/" + model.Extension_Name + "',"); output.push(" long_description=README + '\\n\\n' + HISTORY,"); output.push(" license='MIT',"); output.push(" classifiers=CLASSIFIERS,"); diff --git a/src/test/scenarios/attestation/output/src/attestation/setup.py b/src/test/scenarios/attestation/output/src/attestation/setup.py index 099fbcb3b..809e86795 100644 --- a/src/test/scenarios/attestation/output/src/attestation/setup.py +++ b/src/test/scenarios/attestation/output/src/attestation/setup.py @@ -9,9 +9,12 @@ from codecs import open from setuptools import setup, find_packages -# TODO: Confirm this is the right version number you want and it matches your # HISTORY.rst entry. VERSION = '0.1.0' +try: + from .manual.version import VERSION +except ImportError: + pass # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers @@ -27,8 +30,11 @@ 'License :: OSI Approved :: MIT License', ] -# TODO: Add any additional SDK dependencies here DEPENDENCIES = [] +try: + from .manual.dependency import DEPENDENCIES +except ImportError: + pass with open('README.md', 'r', encoding='utf-8') as f: README = f.read() @@ -39,11 +45,9 @@ name='attestation', version=VERSION, description='Microsoft Azure Command-Line Tools AttestationManagementClient Extension', - # TODO: Update author and email, if applicable author='Microsoft Corporation', author_email='azpycli@microsoft.com', - # TODO: consider pointing directly to your source code instead of the generic repo - url='https://github.com/Azure/azure-cli-extensions', + url='https://github.com/Azure/azure-cli-extensions/tree/master/src/attestation', long_description=README + '\n\n' + HISTORY, license='MIT', classifiers=CLASSIFIERS, diff --git a/src/test/scenarios/datafactory/output/src/datafactory/setup.py b/src/test/scenarios/datafactory/output/src/datafactory/setup.py index efee900f8..5e6f747b9 100644 --- a/src/test/scenarios/datafactory/output/src/datafactory/setup.py +++ b/src/test/scenarios/datafactory/output/src/datafactory/setup.py @@ -9,9 +9,12 @@ from codecs import open from setuptools import setup, find_packages -# TODO: Confirm this is the right version number you want and it matches your # HISTORY.rst entry. VERSION = '0.1.0' +try: + from .manual.version import VERSION +except ImportError: + pass # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers @@ -27,8 +30,11 @@ 'License :: OSI Approved :: MIT License', ] -# TODO: Add any additional SDK dependencies here DEPENDENCIES = [] +try: + from .manual.dependency import DEPENDENCIES +except ImportError: + pass with open('README.md', 'r', encoding='utf-8') as f: README = f.read() @@ -39,11 +45,9 @@ name='datafactory', version=VERSION, description='Microsoft Azure Command-Line Tools DataFactoryManagementClient Extension', - # TODO: Update author and email, if applicable author='Microsoft Corporation', author_email='azpycli@microsoft.com', - # TODO: consider pointing directly to your source code instead of the generic repo - url='https://github.com/Azure/azure-cli-extensions', + url='https://github.com/Azure/azure-cli-extensions/tree/master/src/datafactory', long_description=README + '\n\n' + HISTORY, license='MIT', classifiers=CLASSIFIERS, diff --git a/src/test/scenarios/managed-network/output/src/managed-network/setup.py b/src/test/scenarios/managed-network/output/src/managed-network/setup.py index a4efbafc4..e8564d485 100644 --- a/src/test/scenarios/managed-network/output/src/managed-network/setup.py +++ b/src/test/scenarios/managed-network/output/src/managed-network/setup.py @@ -9,9 +9,12 @@ from codecs import open from setuptools import setup, find_packages -# TODO: Confirm this is the right version number you want and it matches your # HISTORY.rst entry. VERSION = '0.1.0' +try: + from .manual.version import VERSION +except ImportError: + pass # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers @@ -27,8 +30,11 @@ 'License :: OSI Approved :: MIT License', ] -# TODO: Add any additional SDK dependencies here DEPENDENCIES = [] +try: + from .manual.dependency import DEPENDENCIES +except ImportError: + pass with open('README.md', 'r', encoding='utf-8') as f: README = f.read() @@ -39,11 +45,9 @@ name='managed_network', version=VERSION, description='Microsoft Azure Command-Line Tools ManagedNetworkManagementClient Extension', - # TODO: Update author and email, if applicable author='Microsoft Corporation', author_email='azpycli@microsoft.com', - # TODO: consider pointing directly to your source code instead of the generic repo - url='https://github.com/Azure/azure-cli-extensions', + url='https://github.com/Azure/azure-cli-extensions/tree/master/src/managed-network', long_description=README + '\n\n' + HISTORY, license='MIT', classifiers=CLASSIFIERS,