diff --git a/src/plugins/azgenerator/TemplateAzureCliCommands.ts b/src/plugins/azgenerator/TemplateAzureCliCommands.ts index 553d79c32..b4306ec55 100644 --- a/src/plugins/azgenerator/TemplateAzureCliCommands.ts +++ b/src/plugins/azgenerator/TemplateAzureCliCommands.ts @@ -14,8 +14,8 @@ export function GenerateAzureCliCommands(model: CodeModelAz): string[] { let header: HeaderGenerator = new HeaderGenerator(); // this can't be currently reproduced - // header.disableTooManyStatements = true; - // header.disableTooManyLocals = true; + header.disableTooManyStatements = true; + header.disableTooManyLocals = true; header.addFromImport("azure.cli.core.commands", ["CliCommandType"]); let output: string[] = [] diff --git a/src/plugins/azgenerator/TemplateAzureCliCustom.ts b/src/plugins/azgenerator/TemplateAzureCliCustom.ts index 3da1f3b9f..bd3de6635 100644 --- a/src/plugins/azgenerator/TemplateAzureCliCustom.ts +++ b/src/plugins/azgenerator/TemplateAzureCliCustom.ts @@ -32,6 +32,10 @@ export function GenerateAzureCliCustom(model: CodeModelAz): string[] { header.addFromImport("azure.cli.core.util", ["sdk_no_wait"]); } + if(required['disableUnusedArgument']) { + header.disableUnusedArgument = true; + } + let output = []; output = output.concat(body); output.push(""); @@ -68,6 +72,9 @@ function GenerateBody(model: CodeModelAz, required: any): string[] { if (needUpdate) { output = output.concat(GetCommandBody(model, required, needUpdate, originalOperation, needGeneric, genericParameter)); } + if (needGeneric) { + required['disableUnusedArgument'] = true; + } } while (model.SelectNextCommand()); } @@ -335,9 +342,6 @@ function GetSingleCommandBody(model: CodeModelAz, required, originalOperation: O } continue; } - required['json'] = true; - output_body.push(" if isinstance(" + model.MethodParameter_MapsTo + ", str):"); - output_body.push(" " + model.MethodParameter_MapsTo + " = json.loads(" + model.MethodParameter_MapsTo + ")"); } else if (model.MethodParameter_DefaultValue !== undefined && model.MethodParameter_Type != SchemaType.Constant) { // model is simple type with default value diff --git a/src/plugins/azgenerator/TemplateAzureCliParams.ts b/src/plugins/azgenerator/TemplateAzureCliParams.ts index 6b4d5d83d..c7b25bbfb 100644 --- a/src/plugins/azgenerator/TemplateAzureCliParams.ts +++ b/src/plugins/azgenerator/TemplateAzureCliParams.ts @@ -70,10 +70,6 @@ export function GenerateAzureCliParams(model: CodeModelAz): string[] { header.disableTooManyLines = true; header.disableTooManyStatements = true; - if (hasJson) { - header.addFromImport("knack.arguments", ["CLIArgumentType"]); - } - let parameterImports: string[] = []; if (hasTags) parameterImports.push("tags_type"); if (hasBoolean) parameterImports.push("get_three_state_flag"); @@ -82,8 +78,15 @@ export function GenerateAzureCliParams(model: CodeModelAz): string[] { if (hasLocation) parameterImports.push("get_location_type"); header.addFromImport("azure.cli.core.commands.parameters", parameterImports); + let validatorImports: string[] = []; if (hasLocationValidator) { - header.addFromImport('azure.cli.core.commands.validators', ['get_default_location_from_resource_group']); + validatorImports.push("get_default_location_from_resource_group"); + } + if (hasJson) { + validatorImports.push("validate_file_or_dict"); + } + if (validatorImports.length > 0) { + header.addFromImport('azure.cli.core.commands.validators', validatorImports); } if (hasActions) { @@ -153,6 +156,7 @@ function getCommandBody(model: CodeModelAz, needUpdate: boolean = false, needGen } } let baseParam = null; + let hasResourceGroupInOperation = false; if (model.SelectFirstMethodParameter()) { do { if (model.MethodParameter_IsFlattened) { @@ -241,11 +245,11 @@ function getCommandBody(model: CodeModelAz, needUpdate: boolean = false, needGen argument += "])"; } - let hasJsonLastTime = false; let needSkip = false; if (parameterName == "resource_group_name") { argument += ", resource_group_name_type"; hasResourceGroup = true; + hasResourceGroupInOperation = true; needSkip = true; } else if (parameterName == "tags") { argument += ", tags_type"; @@ -253,7 +257,7 @@ function getCommandBody(model: CodeModelAz, needUpdate: boolean = false, needGen needSkip = true; } else if (parameterName == "location") { argument += ", arg_type=get_location_type(self.cli_ctx)"; - if (hasResourceGroup) { + if (hasResourceGroupInOperation) { argument += ", validator=get_default_location_from_resource_group"; hasLocationValidator = true; } @@ -267,8 +271,7 @@ function getCommandBody(model: CodeModelAz, needUpdate: boolean = false, needGen continue; } hasJson = true; - hasJsonLastTime = true; - argument += ", arg_type=CLIArgumentType(options_list=['--" + parameterName.replace(/_/g, '-') + "']"; + argument += ", type=validate_file_or_dict"; } else if (model.MethodParameter_IsList && model.MethodParameter_IsListOfSimple) { let actionName: string = model.Schema_ActionName(model.MethodParameter.schema); argument += ", action=" + actionName; @@ -312,11 +315,7 @@ function getCommandBody(model: CodeModelAz, needUpdate: boolean = false, needGen } } argument += "'"; - - if (hasJsonLastTime) { - argument += ")"; - hasJsonLastTime = false; - } + if (!isNullOrUndefined(baseParam) && model.MethodParameter['polyBaseParam'] == baseParam) { argument += ", arg_group='" + Capitalize(ToCamelCase(model.Parameter_MapsTo(baseParam))) + "'"; } diff --git a/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/commands.py b/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/commands.py index 13f493f3f..3d2e99bf1 100644 --- a/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/commands.py +++ b/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/commands.py @@ -7,6 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is # regenerated. # -------------------------------------------------------------------------- +# pylint: disable=too-many-statements +# pylint: disable=too-many-locals from azure.cli.core.commands import CliCommandType 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 e1b60b307..f44ba0b77 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 @@ -10,14 +10,16 @@ # pylint: disable=too-many-lines # pylint: disable=too-many-statements -from knack.arguments import CLIArgumentType from azure.cli.core.commands.parameters import ( tags_type, get_enum_type, resource_group_name_type, get_location_type ) -from azure.cli.core.commands.validators import get_default_location_from_resource_group +from azure.cli.core.commands.validators import ( + get_default_location_from_resource_group, + validate_file_or_dict +) from azext_datafactory.action import ( AddFactoryVstsConfiguration, AddFactoryGitHubConfiguration, @@ -105,8 +107,8 @@ def load_arguments(self, _): c.argument('trigger_name', options_list=['--name', '-n'], help='The trigger name.') c.argument('if_match', help='ETag of the trigger entity. Should only be specified for update, for which it sho' 'uld match existing entity or can be * for unconditional update.') - c.argument('properties', arg_type=CLIArgumentType(options_list=['--properties'], help='Properties of the trigge' - 'r. Expected value: json-string/@json-file.')) + c.argument('properties', type=validate_file_or_dict, help='Properties of the trigger. Expected value: json-stri' + 'ng/@json-file.') with self.argument_context('datafactory trigger update') as c: c.argument('resource_group_name', resource_group_name_type) @@ -114,8 +116,8 @@ def load_arguments(self, _): c.argument('trigger_name', options_list=['--name', '-n'], help='The trigger name.', id_part='child_name_1') c.argument('if_match', help='ETag of the trigger entity. Should only be specified for update, for which it sho' 'uld match existing entity or can be * for unconditional update.') - c.argument('properties', arg_type=CLIArgumentType(options_list=['--properties'], help='Properties of the trigge' - 'r. Expected value: json-string/@json-file.')) + c.argument('properties', type=validate_file_or_dict, help='Properties of the trigger. Expected value: json-stri' + 'ng/@json-file.') with self.argument_context('datafactory trigger delete') as c: c.argument('resource_group_name', resource_group_name_type) @@ -199,12 +201,10 @@ def load_arguments(self, _): 'itHub repo information.', arg_group='RepoConfiguration') c.argument('fake_identity', action=AddFakeIdentity, nargs='+', help='This is only for az test.') c.argument('zones', nargs='+', help='This is only for az test.') - c.argument('type_properties_compute_properties', arg_type=CLIArgumentType(options_list=['--type-properties-comp' - 'ute-properties'], help='The compute resource for managed integration runtime. Expected value: json-' - 'string/@json-file.')) - c.argument('type_properties_ssis_properties', arg_type=CLIArgumentType(options_list=['--type-properties-ssis-pr' - 'operties'], help='SSIS properties for managed integration runtime. Expected value: json-string/@jso' - 'n-file.')) + c.argument('type_properties_compute_properties', type=validate_file_or_dict, help='The compute resource for man' + 'aged integration runtime. Expected value: json-string/@json-file.') + c.argument('type_properties_ssis_properties', type=validate_file_or_dict, help='SSIS properties for managed int' + 'egration runtime. Expected value: json-string/@json-file.') with self.argument_context('datafactory integration-runtime self-hosted create') as c: c.argument('resource_group_name', resource_group_name_type) @@ -213,9 +213,8 @@ def load_arguments(self, _): c.argument('if_match', help='ETag of the integration runtime entity. Should only be specified for update, for w' 'hich it should match existing entity or can be * for unconditional update.') c.argument('description', help='Integration runtime description.') - c.argument('type_properties_linked_info', arg_type=CLIArgumentType(options_list=['--type-properties-linked-info' - ''], help='The base definition of a linked integration runtime. Expected value: json-string/@json-fi' - 'le.')) + c.argument('type_properties_linked_info', type=validate_file_or_dict, help='The base definition of a linked int' + 'egration runtime. Expected value: json-string/@json-file.') with self.argument_context('datafactory integration-runtime update') as c: c.argument('resource_group_name', resource_group_name_type) diff --git a/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/commands.py b/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/commands.py index b7499f17a..129de3cbf 100644 --- a/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/commands.py +++ b/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/commands.py @@ -7,6 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is # regenerated. # -------------------------------------------------------------------------- +# pylint: disable=too-many-statements +# pylint: disable=too-many-locals from azure.cli.core.commands import CliCommandType diff --git a/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/custom.py b/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/custom.py index 2808694ce..7286926a6 100644 --- a/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/custom.py +++ b/src/test/scenarios/datafactory/output/src/datafactory/azext_datafactory/generated/custom.py @@ -8,6 +8,7 @@ # regenerated. # -------------------------------------------------------------------------- # pylint: disable=too-many-lines +# pylint: disable=unused-argument import json from knack.util import CLIError @@ -150,8 +151,6 @@ def datafactory_trigger_create(client, trigger_name, properties, if_match=None): - if isinstance(properties, str): - properties = json.loads(properties) return client.create_or_update(resource_group_name=resource_group_name, factory_name=factory_name, trigger_name=trigger_name, @@ -300,10 +299,6 @@ def datafactory_integration_runtime_managed_create(client, raise CLIError('at most one of factory_vsts_configuration, factory_git_hub_configuration is needed for repo_co' 'nfiguration!') repo_configuration = all_repo_configuration[0] if len(all_repo_configuration) == 1 else None - if isinstance(type_properties_compute_properties, str): - type_properties_compute_properties = json.loads(type_properties_compute_properties) - if isinstance(type_properties_ssis_properties, str): - type_properties_ssis_properties = json.loads(type_properties_ssis_properties) properties = {} properties['type'] = 'Managed' properties['description'] = description @@ -326,8 +321,6 @@ def datafactory_integration_runtime_self_hosted_create(client, if_match=None, description=None, type_properties_linked_info=None): - if isinstance(type_properties_linked_info, str): - type_properties_linked_info = json.loads(type_properties_linked_info) properties = {} properties['type'] = 'SelfHosted' properties['description'] = description 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 9a010bf9d..3336cd41a 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 @@ -10,13 +10,15 @@ # pylint: disable=too-many-lines # pylint: disable=too-many-statements -from knack.arguments import CLIArgumentType from azure.cli.core.commands.parameters import ( tags_type, resource_group_name_type, get_location_type ) -from azure.cli.core.commands.validators import get_default_location_from_resource_group +from azure.cli.core.commands.validators import ( + get_default_location_from_resource_group, + validate_file_or_dict +) from azext_managed_network.action import ( AddSubscriptions, AddVirtualNetworks, @@ -42,8 +44,8 @@ def load_arguments(self, _): c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group) c.argument('tags', tags_type) - c.argument('properties', arg_type=CLIArgumentType(options_list=['--properties'], help='The MNC properties Expec' - 'ted value: json-string/@json-file.')) + c.argument('properties', type=validate_file_or_dict, help='The MNC properties Expected value: json-string/@json' + '-file.') with self.argument_context('managed-network mn update') as c: c.argument('resource_group_name', resource_group_name_type) @@ -77,8 +79,7 @@ def load_arguments(self, _): 'ype}/{resource-name}\' for a resource.') 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('location', arg_type=get_location_type(self.cli_ctx)) 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 update') as c: @@ -89,8 +90,7 @@ def load_arguments(self, _): 'ype}/{resource-name}\' for a resource.') 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('location', arg_type=get_location_type(self.cli_ctx)) 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: @@ -117,8 +117,8 @@ def load_arguments(self, _): c.argument('group_name', help='The name of the Managed Network Group.') c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group) - c.argument('management_groups', arg_type=CLIArgumentType(options_list=['--management-groups'], help='The collec' - 'tion of management groups covered by the Managed Network Expected value: json-string/@json-file.')) + c.argument('management_groups', type=validate_file_or_dict, help='The collection of management groups covered b' + 'y the Managed Network Expected value: json-string/@json-file.') c.argument('subscriptions', action=AddSubscriptions, nargs='+', help='The collection of subscriptions covered b' 'y the Managed Network') c.argument('virtual_networks', action=AddVirtualNetworks, nargs='+', help='The collection of virtual nets cover' @@ -132,8 +132,8 @@ def load_arguments(self, _): c.argument('group_name', help='The name of the Managed Network Group.', id_part='child_name_1') c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group) - c.argument('management_groups', arg_type=CLIArgumentType(options_list=['--management-groups'], help='The collec' - 'tion of management groups covered by the Managed Network Expected value: json-string/@json-file.')) + c.argument('management_groups', type=validate_file_or_dict, help='The collection of management groups covered b' + 'y the Managed Network Expected value: json-string/@json-file.') c.argument('subscriptions', action=AddSubscriptions, nargs='+', help='The collection of subscriptions covered b' 'y the Managed Network') c.argument('virtual_networks', action=AddVirtualNetworks, nargs='+', help='The collection of virtual nets cover' diff --git a/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/commands.py b/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/commands.py index e37f756e5..f7b34f300 100644 --- a/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/commands.py +++ b/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/commands.py @@ -7,6 +7,8 @@ # Changes may cause incorrect behavior and will be lost if the code is # regenerated. # -------------------------------------------------------------------------- +# pylint: disable=too-many-statements +# pylint: disable=too-many-locals from azure.cli.core.commands import CliCommandType diff --git a/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/custom.py b/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/custom.py index 5e171b992..c49c23d2e 100644 --- a/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/custom.py +++ b/src/test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/custom.py @@ -8,8 +8,8 @@ # regenerated. # -------------------------------------------------------------------------- # pylint: disable=too-many-lines +# pylint: disable=unused-argument -import json from azure.cli.core.util import sdk_no_wait @@ -31,8 +31,6 @@ def managed_network_mn_create(client, location, tags=None, properties=None): - if isinstance(properties, str): - properties = json.loads(properties) return client.create_or_update(resource_group_name=resource_group_name, managed_network_name=managed_network_name, location=location, @@ -134,8 +132,6 @@ def managed_network_mn_group_create(client, virtual_networks=None, subnets=None, no_wait=False): - if isinstance(management_groups, str): - management_groups = json.loads(management_groups) return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name=resource_group_name, @@ -158,8 +154,6 @@ def managed_network_mn_group_update(client, virtual_networks=None, subnets=None, no_wait=False): - if isinstance(management_groups, str): - management_groups = json.loads(management_groups) return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name=resource_group_name,