Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
Support group modifier (#298)
Browse files Browse the repository at this point in the history
* clear output-folder

* small fix

* change back managed-network

* doc update

* add faq

* add test recordings

* remove the unused code

* bump to 1.3

* clicommon 0.4.6

* change faq

* support group modifer

* add test for group modifier

* add test
  • Loading branch information
qiaozha authored Apr 9, 2020
1 parent 38fed80 commit 1448110
Show file tree
Hide file tree
Showing 15 changed files with 342 additions and 341 deletions.
19 changes: 17 additions & 2 deletions src/plugins/modifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ let directives: Array<any> = [];
interface WhereCommandDirective {
select?: string;
where: {
"group": string;
"group-description": string;
"command"?: string;
"command-description"?: string;
"parameter-name"?: string;
"parameter-description"?: string;
};
set?: {
"group": string;
"group-description": string;
"command"?: string;
"command-description"?: string;
"parameter-name"?: string;
Expand Down Expand Up @@ -71,7 +75,7 @@ function isWhereCommandDirective(it: any): it is WhereCommandDirective {
const directive = it;
const where = directive.where;
const set = directive.set;
if (where && (where["command"] || where['parameter-name'])) {
if (where && (where["command"] || where['parameter-name'] || where['group'])) {
const prohibitedFilters = [
"model-name",
"property-name",
Expand Down Expand Up @@ -123,18 +127,29 @@ export class Modifiers {
};
if (isWhereCommandDirective(directive)) {
const selectType = directive.select;
const groupRegex = getPatternToMatch(directive.where["group"]);
const parameterRegex = getPatternToMatch(directive.where["parameter-name"]);
const commandRegex = getPatternToMatch(directive.where["command"]);
const parameterReplacer = directive.set !== undefined? directive.set["parameter-name"]: undefined;
const paramDescriptionReplacer = directive.set !== undefined? directive.set["parameter-description"]: undefined;
const commandReplacer = directive.set !== undefined ? directive.set["command"] : undefined;
const commandDescriptionReplacer = directive.set !== undefined? directive.set["command-description"]: undefined;
const groupReplacer = directive.set !== undefined ? directive.set["group"] : undefined;
const groupDescriptionReplacer = directive.set !== undefined? directive.set["group-description"]: undefined;

for (const operationGroup of values(this.codeModel.operationGroups)) {
//operationGroup

let groupChanged = false;
if (!isNullOrUndefined(operationGroup.language['az']['command']) && operationGroup.language['az']['command'].match(groupRegex)) {
operationGroup.language['az']['command'] = groupReplacer? groupRegex? operationGroup.language['az']['command'].replace(groupRegex, groupReplacer): groupReplacer: operationGroup.language['az']['command'];
operationGroup.language['az']['description'] = groupDescriptionReplacer? groupDescriptionReplacer: operationGroup.language['az']['description'];
groupChanged = true;
}
for (const operation of values(operationGroup.operations)) {
//operation
if (groupChanged) {
operation.language['az']['command'] = operationGroup.language['az']['command'] + " " + operation.language['az']['name'];
}
if (operation.language['az']['command'] != undefined && operation.language["az"]["command"].match(commandRegex)) {
operation.language["az"]["command"] = commandReplacer? commandRegex? operation.language["az"]["command"].replace(commandRegex, commandReplacer): commandReplacer: operation.language["az"]["command"];
operation.language["az"]["description"] = commandDescriptionReplacer? commandDescriptionReplacer: operation.language["az"]["description"];
Expand Down
7 changes: 7 additions & 0 deletions src/test/scenarios/datafactory/configuration/readme.az.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ az:
package-name: azure-mgmt-datafactory
namespace: azure.mgmt.datafactory
python-sdk-output-folder: "$(output-folder)/azext_datafactory/vendored_sdks/datafactory"

directive:
- where:
group: datafactory factory
set:
group: datafactory

```
Original file line number Diff line number Diff line change
Expand Up @@ -12,88 +12,87 @@
from knack.help_files import helps


helps['datafactory factory'] = """
helps['datafactory'] = """
type: group
short-summary: datafactory factory
short-summary: datafactory
"""

helps['datafactory factory list'] = """
helps['datafactory list'] = """
type: command
short-summary: Lists factories under the specified subscription.
examples:
- name: Factories_ListByResourceGroup
text: |-
az datafactory factory list --resource-group "exampleResourceGroup"
az datafactory list --resource-group "exampleResourceGroup"
"""

helps['datafactory factory show'] = """
helps['datafactory show'] = """
type: command
short-summary: Gets a factory.
examples:
- name: Factories_Get
text: |-
az datafactory factory show --factory-name "exampleFactoryName" --resource-group "exampleResourceGroup"
az datafactory show --factory-name "exampleFactoryName" --resource-group "exampleResourceGroup"
"""

helps['datafactory factory create'] = """
helps['datafactory create'] = """
type: command
short-summary: Creates or updates a factory.
examples:
- name: Factories_CreateOrUpdate
text: |-
az datafactory factory create --location "East US" --factory-name "exampleFactoryName" --resource-group \
"exampleResourceGroup"
az datafactory create --location "East US" --factory-name "exampleFactoryName" --resource-group "example\
ResourceGroup"
"""

helps['datafactory factory update'] = """
helps['datafactory update'] = """
type: command
short-summary: Updates a factory.
examples:
- name: Factories_Update
text: |-
az datafactory factory update --factory-name "exampleFactoryName" --tags exampleTag="exampleValue" --res\
ource-group "exampleResourceGroup"
az datafactory update --factory-name "exampleFactoryName" --tags exampleTag="exampleValue" --resource-gr\
oup "exampleResourceGroup"
"""

helps['datafactory factory delete'] = """
helps['datafactory delete'] = """
type: command
short-summary: Deletes a factory.
examples:
- name: Factories_Delete
text: |-
az datafactory factory delete --factory-name "exampleFactoryName" --resource-group "exampleResourceGroup\
"
az datafactory delete --factory-name "exampleFactoryName" --resource-group "exampleResourceGroup"
"""

helps['datafactory factory configure-factory-repo'] = """
helps['datafactory configure-factory-repo'] = """
type: command
short-summary: Updates a factory's repo information.
examples:
- name: Factories_ConfigureFactoryRepo
text: |-
az datafactory factory configure-factory-repo --factory-resource-id "/subscriptions/12345678-1234-1234-1\
234-12345678abc/resourceGroups/exampleResourceGroup/providers/Microsoft.DataFactory/factories/exampleFactoryName" --fac\
tory-vsts-configuration account-name="ADF" collaboration-branch="master" last-commit-id="" project-name="project" repos\
itory-name="repo" root-folder="/" tenant-id="" --location-id "East US"
az datafactory configure-factory-repo --factory-resource-id "/subscriptions/12345678-1234-1234-1234-1234\
5678abc/resourceGroups/exampleResourceGroup/providers/Microsoft.DataFactory/factories/exampleFactoryName" --factory-vst\
s-configuration account-name="ADF" collaboration-branch="master" last-commit-id="" project-name="project" repository-na\
me="repo" root-folder="/" tenant-id="" --location-id "East US"
"""

helps['datafactory factory get-data-plane-access'] = """
helps['datafactory get-data-plane-access'] = """
type: command
short-summary: Get Data Plane access.
examples:
- name: Factories_GetDataPlaneAccess
text: |-
az datafactory factory get-data-plane-access --factory-name "exampleFactoryName" --access-resource-path \
"" --expire-time "2018-11-10T09:46:20.2659347Z" --permissions "r" --profile-name "DefaultProfile" --start-time "2018-11\
-10T02:46:20.2659347Z" --resource-group "exampleResourceGroup"
az datafactory get-data-plane-access --factory-name "exampleFactoryName" --access-resource-path "" --exp\
ire-time "2018-11-10T09:46:20.2659347Z" --permissions "r" --profile-name "DefaultProfile" --start-time "2018-11-10T02:4\
6:20.2659347Z" --resource-group "exampleResourceGroup"
"""

helps['datafactory factory get-git-hub-access-token'] = """
helps['datafactory get-git-hub-access-token'] = """
type: command
short-summary: Get GitHub Access Token.
examples:
- name: Factories_GetGitHubAccessToken
text: |-
az datafactory factory get-git-hub-access-token --factory-name "exampleFactoryName" --git-hub-access-cod\
e "some" --git-hub-access-token-base-url "some" --git-hub-client-id "some" --resource-group "exampleResourceGroup"
az datafactory get-git-hub-access-token --factory-name "exampleFactoryName" --git-hub-access-code "some"\
--git-hub-access-token-base-url "some" --git-hub-client-id "some" --resource-group "exampleResourceGroup"
"""
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@

def load_arguments(self, _):

with self.argument_context('datafactory factory list') as c:
with self.argument_context('datafactory list') as c:
c.argument('resource_group_name', resource_group_name_type)

with self.argument_context('datafactory factory show') as c:
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('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 factory create') as c:
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('if_match', help='ETag of the factory entity. Should only be specified for update, for which it shou'
Expand All @@ -49,25 +49,25 @@ def load_arguments(self, _):
c.argument('factory_git_hub_configuration', action=AddFactoryGitHubConfiguration, nargs='+', help='Factory\'s G'
'itHub repo information.', arg_group='RepoConfiguration')

with self.argument_context('datafactory factory update') as c:
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('tags', tags_type)
c.argument('identity', action=AddIdentity, nargs='+', help='Managed service identity of the factory.')

with self.argument_context('datafactory factory delete') as c:
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.')

with self.argument_context('datafactory factory configure-factory-repo') as c:
with self.argument_context('datafactory configure-factory-repo') as c:
c.argument('location_id', help='The location identifier.')
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.', arg_group='RepoConfiguration')
c.argument('factory_git_hub_configuration', action=AddFactoryGitHubConfiguration, nargs='+', help='Factory\'s G'
'itHub repo information.', arg_group='RepoConfiguration')

with self.argument_context('datafactory factory get-data-plane-access') as c:
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('permissions', help='The string with permissions for Data Plane access. Currently only \'r\' is supp'
Expand All @@ -80,7 +80,7 @@ def load_arguments(self, _):
c.argument('expire_time', help='Expiration time for the token. Maximum duration for the token is eight hours an'
'd by default the token will expire in eight hours.')

with self.argument_context('datafactory factory get-git-hub-access-token') as c:
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('git_hub_access_code', help='GitHub access code.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ def load_command_table(self, _):
operations_tmpl='azext_datafactory.vendored_sdks.datafactory.operations._factory_operations#FactoryOperations.{'
'}',
client_factory=cf_factory)
with self.command_group('datafactory factory', datafactory_factory, client_factory=cf_factory,
is_experimental=True) as g:
g.custom_command('list', 'datafactory_factory_list')
g.custom_show_command('show', 'datafactory_factory_show')
g.custom_command('create', 'datafactory_factory_create')
g.custom_command('update', 'datafactory_factory_update')
g.custom_command('delete', 'datafactory_factory_delete')
g.custom_command('configure-factory-repo', 'datafactory_factory_configure_factory_repo')
g.custom_command('get-data-plane-access', 'datafactory_factory_get_data_plane_access')
g.custom_command('get-git-hub-access-token', 'datafactory_factory_get_git_hub_access_token')
with self.command_group('datafactory', datafactory_factory, client_factory=cf_factory) as g:
g.custom_command('list', 'datafactory_list')
g.custom_show_command('show', 'datafactory_show')
g.custom_command('create', 'datafactory_create')
g.custom_command('update', 'datafactory_update')
g.custom_command('delete', 'datafactory_delete')
g.custom_command('configure-factory-repo', 'datafactory_configure_factory_repo')
g.custom_command('get-data-plane-access', 'datafactory_get_data_plane_access')
g.custom_command('get-git-hub-access-token', 'datafactory_get_git_hub_access_token')
Loading

0 comments on commit 1448110

Please sign in to comment.