From bb4f3de6be75e35e8b59739afc4d99a8c41f3309 Mon Sep 17 00:00:00 2001 From: qiaozha Date: Thu, 30 Apr 2020 15:19:06 +0800 Subject: [PATCH 1/4] parse-resource-id --- src/utils/helper.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/utils/helper.ts b/src/utils/helper.ts index 88f30869c..72238dc97 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -3,6 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as fs from 'fs'; +import { createDiffieHellman } from 'crypto'; +import { Key } from 'readline'; +import { Dictionary } from '@azure-tools/linq'; export function changeCamelToDash(str: string) { str = str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`); @@ -214,4 +217,27 @@ export function ToMultiLine(sentence: string, output: string[] = undefined, maxL for (let line of ret) output.push(line); } return ret; +} + + +export function parse_resource_id(path: string) { + let baseRegex: RegExp = /\/subscriptions\/(?[^\/]*)(\/resourceGroups\/(?[^\/]*))?(\/providers\/(?[^\/]*)\/(?[^\/]*)\/(?[^\/]*)(?.*))?/gi; + let childRegex: RegExp = /(\/providers\/(?[^\/]*))?\/(?[^\/]*)\/(?[^\/]*)/gi; + let mp: RegExpExecArray = baseRegex.exec(path); + if (mp) { + let groups = mp.groups; + let children: RegExpExecArray = null; + let count = 0; + let childStr: string = groups["children"]; + let result = null; + while (result = childRegex.exec(childStr)) { + count++; + for(let key of ['child_namespace', 'child_type', 'child_name']) { + groups[key + "_" + count] = result["groups"][key]; + } + } + groups["last_child_num"] = "" + count; + return groups; + } + return {}; } \ No newline at end of file From 8e965cfe8d2f9c29e5e3548310f952cd42823a86 Mon Sep 17 00:00:00 2001 From: qiaozha Date: Wed, 6 May 2020 10:36:54 +0800 Subject: [PATCH 2/4] support ids --- src/plugins/azgenerator/CodeModelAzImpl.ts | 4 +++- src/utils/helper.ts | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/plugins/azgenerator/CodeModelAzImpl.ts b/src/plugins/azgenerator/CodeModelAzImpl.ts index 1ebda9ef1..798282328 100644 --- a/src/plugins/azgenerator/CodeModelAzImpl.ts +++ b/src/plugins/azgenerator/CodeModelAzImpl.ts @@ -7,7 +7,7 @@ import { CodeModelAz, CommandExample, ExampleParam, MethodParam } from "./CodeMo import { CodeModel, SchemaType, Schema, ParameterLocation, Operation, Value, Parameter, VirtualParameter, Property, Request, OperationGroup } from '@azure-tools/codemodel'; import { serialize, deserialize, EnglishPluralizationService, pascalCase } from "@azure-tools/codegen"; import { Session, startSession, Host, Channel } from "@azure-tools/autorest-extension-base"; -import { ToSnakeCase, deepCopy, ToJsonString, Capitalize, ToCamelCase, EscapeString } from '../../utils/helper'; +import { ToSnakeCase, deepCopy, ToJsonString, Capitalize, ToCamelCase, EscapeString, parseResourceId } from '../../utils/helper'; import { values } from "@azure-tools/linq"; import { GenerateDefaultTestScenario, ResourcePool, GenerateDefaultTestScenarioByDependency } from './ScenarioTool' import { timingSafeEqual } from "crypto"; @@ -146,9 +146,11 @@ export class CodeModelCliImpl implements CodeModelAz { } } if (this.SelectFirstMethod()) { + let id_groups = parseResourceId(this.Method.requests[0].protocol.http.path); if (this.SelectFirstMethodParameter()) { do { let parameters = this.MethodParameter; + let defaultName = parameters.language['cli']['cliKey']; if (parameters.language['cli'].required) { this.MethodParameter['RequiredByMethod'] = true; } else { diff --git a/src/utils/helper.ts b/src/utils/helper.ts index 72238dc97..41b8eceaa 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -220,12 +220,19 @@ export function ToMultiLine(sentence: string, output: string[] = undefined, maxL } -export function parse_resource_id(path: string) { +export function parseResourceId(path: string): Map { let baseRegex: RegExp = /\/subscriptions\/(?[^\/]*)(\/resourceGroups\/(?[^\/]*))?(\/providers\/(?[^\/]*)\/(?[^\/]*)\/(?[^\/]*)(?.*))?/gi; let childRegex: RegExp = /(\/providers\/(?[^\/]*))?\/(?[^\/]*)\/(?[^\/]*)/gi; let mp: RegExpExecArray = baseRegex.exec(path); + let ret = new Map(); if (mp) { let groups = mp.groups; + ret.set('subscription', groups['subscription']); + ret.set('resource_group', groups['resource_group']); + ret.set('namespace', groups['namespace']); + ret.set('type', groups['type']); + ret.set('name', groups['name']); + ret.set('children', groups['children']); let children: RegExpExecArray = null; let count = 0; let childStr: string = groups["children"]; @@ -233,11 +240,11 @@ export function parse_resource_id(path: string) { while (result = childRegex.exec(childStr)) { count++; for(let key of ['child_namespace', 'child_type', 'child_name']) { - groups[key + "_" + count] = result["groups"][key]; - } + ret.set(key + "_" + count, result["groups"][key]); + } } - groups["last_child_num"] = "" + count; - return groups; + ret.set("last_child_num", "" + count); + return ret; } - return {}; + return ret; } \ No newline at end of file From 32e485ddf5e6d32ad2c79d985a4f1176e21e609b Mon Sep 17 00:00:00 2001 From: qiaozha Date: Wed, 6 May 2020 13:56:33 +0800 Subject: [PATCH 3/4] support ids --- src/plugins/azgenerator/CodeModelAz.ts | 1 + src/plugins/azgenerator/CodeModelAzImpl.ts | 19 +++++++++++++- .../azgenerator/TemplateAzureCliParams.ts | 4 ++- src/plugins/aznamer.ts | 7 ++++-- .../azext_attestation/generated/_params.py | 4 +-- .../azext_datafactory/generated/_params.py | 6 ++--- .../generated/_params.py | 25 +++++++++++-------- src/utils/helper.ts | 14 ++++++----- 8 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/plugins/azgenerator/CodeModelAz.ts b/src/plugins/azgenerator/CodeModelAz.ts index 0ab0a50ec..0c5b3fe66 100644 --- a/src/plugins/azgenerator/CodeModelAz.ts +++ b/src/plugins/azgenerator/CodeModelAz.ts @@ -119,6 +119,7 @@ export interface CodeModelAz MethodParameter_IsList: boolean; MethodParameter_IsSimpleArray: boolean; MethodParameter_IsListOfSimple: boolean; + MethodParameter_IdPart: string; MethodParameter: Parameter; MethodParameters: Array; SubMethodParameter: Parameter; diff --git a/src/plugins/azgenerator/CodeModelAzImpl.ts b/src/plugins/azgenerator/CodeModelAzImpl.ts index 798282328..6d1b43acc 100644 --- a/src/plugins/azgenerator/CodeModelAzImpl.ts +++ b/src/plugins/azgenerator/CodeModelAzImpl.ts @@ -146,11 +146,24 @@ export class CodeModelCliImpl implements CodeModelAz { } } if (this.SelectFirstMethod()) { - let id_groups = parseResourceId(this.Method.requests[0].protocol.http.path); + let id_groups = new Map(); + if(this.Method_NameAz == 'show' || this.Method_NameAz == 'create' || this.Method_NameAz == 'update') { + id_groups = parseResourceId(this.session, this.Request.protocol.http.path); + } + if (this.SelectFirstMethodParameter()) { do { let parameters = this.MethodParameter; let defaultName = parameters.language['cli']['cliKey']; + let defaultToMatch = '{' + defaultName + '}'; + + if(!isNullOrUndefined(id_groups)) { + for(let k of id_groups.entries()) { + if(k[1] == defaultToMatch && defaultName != 'resourceGroupName') { + this.MethodParameter.language['az']['id_part'] = k[0]; + } + } + } if (parameters.language['cli'].required) { this.MethodParameter['RequiredByMethod'] = true; } else { @@ -884,6 +897,10 @@ export class CodeModelCliImpl implements CodeModelAz { return this.Parameter_NameAz(this.MethodParameter); } + public get MethodParameter_IdPart(): string { + return this.MethodParameter.language['az']['id_part']; + } + public get MethodParameter_IsArray(): boolean { if (this.submethodparameters != null) { return this.submethodparameters[this.currentSubOptionIndex].schema?.type == SchemaType.Array; diff --git a/src/plugins/azgenerator/TemplateAzureCliParams.ts b/src/plugins/azgenerator/TemplateAzureCliParams.ts index 91fe36456..a26cb9e42 100644 --- a/src/plugins/azgenerator/TemplateAzureCliParams.ts +++ b/src/plugins/azgenerator/TemplateAzureCliParams.ts @@ -318,7 +318,9 @@ function getCommandBody(model: CodeModelAz, needUpdate: boolean = false, needGen argument += ", arg_group='" + Capitalize(ToCamelCase(model.Parameter_MapsTo(baseParam))) + "'"; } } - + if(!isNullOrUndefined(model.MethodParameter_IdPart)) { + argument += ", id_part='" + model.MethodParameter_IdPart + "'"; + } argument += ")"; ToMultiLine(argument, output_args); diff --git a/src/plugins/aznamer.ts b/src/plugins/aznamer.ts index 385227458..f927dfe01 100644 --- a/src/plugins/aznamer.ts +++ b/src/plugins/aznamer.ts @@ -72,7 +72,10 @@ export class AzNamer { obj.language['az']['name'] = obj.language['cli']? obj.language['cli']['name']: obj.language['python']['name']; obj.language['az']['name'] = changeCamelToDash(obj.language['az']['name']); obj.language['az']['mapsto'] = obj.language['az']['name'].replace(/-/g, '_'); - obj.language['az']['description'] = obj.language['cli']? obj.language['cli']['description']: obj.language['python']['description'];; + obj.language['az']['description'] = obj.language['cli']? obj.language['cli']['description']: obj.language['python']['description']; + if(!isNullOrUndefined(obj.language['cli']['id_part'])) { + obj.language['az']['id_part'] = obj.language['cli']['id_part']; + } } processGlobalParam() { @@ -165,7 +168,7 @@ export class AzNamer { }); operation.requests.forEach(request => { let operationName = ""; - if(operation.language['cli'] != undefined) { + if(!isNullOrUndefined(operation.language['cli'])) { operation.language['az'] = new Language(); let commandName = this.methodMap(operation.language['cli']['name'], request.protocol.http.method); operation.language['az']['name'] = commandName; diff --git a/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/_params.py b/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/_params.py index c3fd2210f..fd2533720 100644 --- a/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/_params.py +++ b/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/_params.py @@ -41,11 +41,11 @@ def load_arguments(self, _): with self.argument_context('attestation attestation-provider show') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('provider_name', help='Name of the attestation service instance') + c.argument('provider_name', help='Name of the attestation service instance', id_part='name') with self.argument_context('attestation attestation-provider update') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('provider_name', help='Name of the attestation service') + c.argument('provider_name', help='Name of the attestation service', id_part='name') c.argument('tags', tags_type) with self.argument_context('attestation attestation-provider delete') as c: 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 6a8698d9e..85eedbbda 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 @@ -32,13 +32,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', options_list=['--name', '-n'], help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.', id_part='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', options_list=['--name', '-n'], help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.', id_part='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), @@ -59,7 +59,7 @@ 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', options_list=['--name', '-n'], help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.', id_part='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 ...') 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 d8475c9b0..4b5ccd0ee 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,13 @@ 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', options_list=['--name', '-n'], help='The name of the Managed Network.') + c.argument('managed_network_name', options_list=['--name', '-n'], help='The name of the Managed Network.', + id_part='name') with self.argument_context('managed-network mn create') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('managed_network_name', options_list=['--name', '-n'], help='The name of the Managed Network.') + c.argument('managed_network_name', options_list=['--name', '-n'], help='The name of the Managed Network.', + id_part='name') c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group) c.argument('tags', tags_type) @@ -51,7 +53,8 @@ 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', options_list=['--name', '-n'], help='The name of the Managed Network.') + c.argument('managed_network_name', options_list=['--name', '-n'], help='The name of the Managed Network.', + id_part='name') c.argument('tags', tags_type) with self.argument_context('managed-network mn delete') as c: @@ -105,13 +108,13 @@ def load_arguments(self, _): with self.argument_context('managed-network mn group 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('group_name', help='The name of the Managed Network Group.') + c.argument('managed_network_name', help='The name of the Managed Network.', id_part='name') + c.argument('group_name', help='The name of the Managed Network Group.', id_part='child_name_1') with self.argument_context('managed-network mn group 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('group_name', help='The name of the Managed Network Group.') + c.argument('managed_network_name', help='The name of the Managed Network.', id_part='name') + 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' @@ -125,8 +128,8 @@ def load_arguments(self, _): with self.argument_context('managed-network mn group 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('group_name', help='The name of the Managed Network Group.') + c.argument('managed_network_name', help='The name of the Managed Network.', id_part='name') + 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' @@ -153,8 +156,8 @@ def load_arguments(self, _): with self.argument_context('managed-network managed-network-peering-policy 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('policy_name', help='The name of the Managed Network Peering Policy.') + c.argument('managed_network_name', help='The name of the Managed Network.', id_part='name') + c.argument('policy_name', help='The name of the Managed Network Peering Policy.', id_part='child_name_1') with self.argument_context('managed-network managed-network-peering-policy hub-and-spoke-topology create') as c: c.argument('resource_group_name', resource_group_name_type) diff --git a/src/utils/helper.ts b/src/utils/helper.ts index 41b8eceaa..16168c65a 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -6,6 +6,9 @@ import * as fs from 'fs'; import { createDiffieHellman } from 'crypto'; import { Key } from 'readline'; import { Dictionary } from '@azure-tools/linq'; +import { Channel, Session } from '@azure-tools/autorest-extension-base'; +import { CodeModel } from '@azure-tools/codemodel'; +import { serialize, deserialize, EnglishPluralizationService, pascalCase } from "@azure-tools/codegen"; export function changeCamelToDash(str: string) { str = str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`); @@ -220,11 +223,11 @@ export function ToMultiLine(sentence: string, output: string[] = undefined, maxL } -export function parseResourceId(path: string): Map { - let baseRegex: RegExp = /\/subscriptions\/(?[^\/]*)(\/resourceGroups\/(?[^\/]*))?(\/providers\/(?[^\/]*)\/(?[^\/]*)\/(?[^\/]*)(?.*))?/gi; - let childRegex: RegExp = /(\/providers\/(?[^\/]*))?\/(?[^\/]*)\/(?[^\/]*)/gi; - let mp: RegExpExecArray = baseRegex.exec(path); - let ret = new Map(); +export function parseResourceId(session: Session, mpath: string): Map { + let baseRegex: RegExp = /\/subscriptions\/(?[^\/]*)(\/resourceGroups\/(?[^\/]*))?(\/providers\/(?[^\/]*)\/(?[^\/]*)\/(?[^\/]*)(?.*))?/g; + let childRegex: RegExp = /(\/providers\/(?[^\/]*))?\/(?[^\/]*)\/(?[^\/]*)/g; + let mp: RegExpExecArray = baseRegex.exec(mpath); + let ret: Map = new Map(); if (mp) { let groups = mp.groups; ret.set('subscription', groups['subscription']); @@ -244,7 +247,6 @@ export function parseResourceId(path: string): Map { } } ret.set("last_child_num", "" + count); - return ret; } return ret; } \ No newline at end of file From 344a22f8ce6d683fee34722559edb26d54a57d55 Mon Sep 17 00:00:00 2001 From: qiaozha Date: Wed, 6 May 2020 14:47:48 +0800 Subject: [PATCH 4/4] support ids --- src/plugins/azgenerator/CodeModelAzImpl.ts | 4 +-- .../azgenerator/TemplateAzureCliParams.ts | 7 +++-- .../azext_attestation/generated/_params.py | 2 +- .../azext_datafactory/generated/_params.py | 10 +++---- .../generated/_params.py | 26 +++++++++---------- src/utils/helper.ts | 8 +----- 6 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/plugins/azgenerator/CodeModelAzImpl.ts b/src/plugins/azgenerator/CodeModelAzImpl.ts index 6d1b43acc..b9078e0e0 100644 --- a/src/plugins/azgenerator/CodeModelAzImpl.ts +++ b/src/plugins/azgenerator/CodeModelAzImpl.ts @@ -147,9 +147,7 @@ export class CodeModelCliImpl implements CodeModelAz { } if (this.SelectFirstMethod()) { let id_groups = new Map(); - if(this.Method_NameAz == 'show' || this.Method_NameAz == 'create' || this.Method_NameAz == 'update') { - id_groups = parseResourceId(this.session, this.Request.protocol.http.path); - } + id_groups = parseResourceId(this.Request.protocol.http.path); if (this.SelectFirstMethodParameter()) { do { diff --git a/src/plugins/azgenerator/TemplateAzureCliParams.ts b/src/plugins/azgenerator/TemplateAzureCliParams.ts index a26cb9e42..c3461f280 100644 --- a/src/plugins/azgenerator/TemplateAzureCliParams.ts +++ b/src/plugins/azgenerator/TemplateAzureCliParams.ts @@ -318,9 +318,12 @@ function getCommandBody(model: CodeModelAz, needUpdate: boolean = false, needGen argument += ", arg_group='" + Capitalize(ToCamelCase(model.Parameter_MapsTo(baseParam))) + "'"; } } - if(!isNullOrUndefined(model.MethodParameter_IdPart)) { - argument += ", id_part='" + model.MethodParameter_IdPart + "'"; + if(!model.Method_NameAz.startsWith('list') && !model.Method_NameAz.split(' ').last.startsWith('create') || needUpdate) { + if(!isNullOrUndefined(model.MethodParameter_IdPart)) { + argument += ", id_part='" + model.MethodParameter_IdPart + "'"; + } } + argument += ")"; ToMultiLine(argument, output_args); diff --git a/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/_params.py b/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/_params.py index fd2533720..cd1b5218a 100644 --- a/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/_params.py +++ b/src/test/scenarios/attestation/output/src/attestation/azext_attestation/generated/_params.py @@ -50,7 +50,7 @@ def load_arguments(self, _): with self.argument_context('attestation attestation-provider delete') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('provider_name', help='Name of the attestation service') + c.argument('provider_name', help='Name of the attestation service', id_part='name') with self.argument_context('attestation attestation-provider list-attestation') as c: c.argument('resource_group_name', resource_group_name_type) 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 85eedbbda..456f475b1 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 @@ -38,7 +38,7 @@ def load_arguments(self, _): with self.argument_context('datafactory create') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.', id_part='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), @@ -66,10 +66,10 @@ def load_arguments(self, _): with self.argument_context('datafactory delete') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.', id_part='name') with self.argument_context('datafactory configure-factory-repo') as c: - c.argument('location_id', help='The location identifier.') + c.argument('location_id', help='The location identifier.', id_part='name') c.argument('factory_resource_id', help='The factory resource id.') c.argument('factory_vsts_configuration', action=AddFactoryVstsConfiguration, nargs='+', help='Factory\'s VSTS r' 'epo information. Expect value: KEY1=VALUE1 KEY2=VALUE2 ... , available KEYs are: project-name, tena' @@ -82,7 +82,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', options_list=['--name', '-n'], help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.', id_part='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' @@ -95,7 +95,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', options_list=['--name', '-n'], help='The factory name.') + c.argument('factory_name', options_list=['--name', '-n'], help='The factory name.', id_part='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 4b5ccd0ee..43d3d26e9 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 @@ -43,8 +43,7 @@ def load_arguments(self, _): with self.argument_context('managed-network mn create') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('managed_network_name', options_list=['--name', '-n'], help='The name of the Managed Network.', - id_part='name') + 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) @@ -59,7 +58,8 @@ def load_arguments(self, _): with self.argument_context('managed-network mn delete') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('managed_network_name', options_list=['--name', '-n'], help='The name of the Managed Network.') + c.argument('managed_network_name', options_list=['--name', '-n'], help='The name of the Managed Network.', + id_part='name') with self.argument_context('managed-network mn scope-assignment list') as c: c.argument('scope', help='The base resource of the scope assignment.') @@ -113,8 +113,8 @@ def load_arguments(self, _): with self.argument_context('managed-network mn group create') as c: c.argument('resource_group_name', resource_group_name_type) - c.argument('managed_network_name', help='The name of the Managed Network.', id_part='name') - c.argument('group_name', help='The name of the Managed Network Group.', id_part='child_name_1') + c.argument('managed_network_name', help='The name of the Managed Network.') + 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' @@ -143,8 +143,8 @@ def load_arguments(self, _): with self.argument_context('managed-network mn group 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('group_name', help='The name of the Managed Network Group.') + c.argument('managed_network_name', help='The name of the Managed Network.', id_part='name') + c.argument('group_name', help='The name of the Managed Network Group.', id_part='child_name_1') with self.argument_context('managed-network managed-network-peering-policy list') as c: c.argument('resource_group_name', resource_group_name_type) @@ -173,8 +173,8 @@ def load_arguments(self, _): with self.argument_context('managed-network managed-network-peering-policy hub-and-spoke-topology 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('policy_name', help='The name of the Managed Network Peering Policy.') + c.argument('managed_network_name', help='The name of the Managed Network.', id_part='name') + c.argument('policy_name', help='The name of the Managed Network Peering Policy.', 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('hub', action=AddHub, nargs='+', @@ -198,8 +198,8 @@ def load_arguments(self, _): with self.argument_context('managed-network managed-network-peering-policy mesh-topology 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('policy_name', help='The name of the Managed Network Peering Policy.') + c.argument('managed_network_name', help='The name of the Managed Network.', id_part='name') + c.argument('policy_name', help='The name of the Managed Network Peering Policy.', 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('hub', action=AddHub, nargs='+', @@ -211,5 +211,5 @@ def load_arguments(self, _): with self.argument_context('managed-network managed-network-peering-policy 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('policy_name', help='The name of the Managed Network Peering Policy.') + c.argument('managed_network_name', help='The name of the Managed Network.', id_part='name') + c.argument('policy_name', help='The name of the Managed Network Peering Policy.', id_part='child_name_1') diff --git a/src/utils/helper.ts b/src/utils/helper.ts index 16168c65a..868fb8b5a 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -3,12 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as fs from 'fs'; -import { createDiffieHellman } from 'crypto'; -import { Key } from 'readline'; -import { Dictionary } from '@azure-tools/linq'; -import { Channel, Session } from '@azure-tools/autorest-extension-base'; -import { CodeModel } from '@azure-tools/codemodel'; -import { serialize, deserialize, EnglishPluralizationService, pascalCase } from "@azure-tools/codegen"; export function changeCamelToDash(str: string) { str = str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`); @@ -223,7 +217,7 @@ export function ToMultiLine(sentence: string, output: string[] = undefined, maxL } -export function parseResourceId(session: Session, mpath: string): Map { +export function parseResourceId(mpath: string): Map { let baseRegex: RegExp = /\/subscriptions\/(?[^\/]*)(\/resourceGroups\/(?[^\/]*))?(\/providers\/(?[^\/]*)\/(?[^\/]*)\/(?[^\/]*)(?.*))?/g; let childRegex: RegExp = /(\/providers\/(?[^\/]*))?\/(?[^\/]*)\/(?[^\/]*)/g; let mp: RegExpExecArray = baseRegex.exec(mpath);