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

Commit

Permalink
Merge pull request #333 from Azure/fix-issue-282-273
Browse files Browse the repository at this point in the history
fix-issue-282-273
  • Loading branch information
Zim Kalinowski authored Apr 23, 2020
2 parents f8d15ac + 33d3e25 commit 165e8fd
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/plugins/azgenerator/CodeModelAz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface CodeModelAz
CommandGroup: OperationGroup;
CommandGroup_Name: string;
CommandGroup_Help: string;
CommandGroup_DefaultName: string;

SelectFirstCommand(): boolean;
SelectNextCommand(): boolean;
Expand Down
32 changes: 31 additions & 1 deletion src/plugins/azgenerator/TemplateAzureCliParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()";
Expand Down
14 changes: 9 additions & 5 deletions src/plugins/azgenerator/TemplateAzureCliSetupPy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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()");
Expand All @@ -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='[email protected]',");
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,");
Expand Down
14 changes: 9 additions & 5 deletions src/test/scenarios/attestation/output/src/attestation/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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='[email protected]',
# 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,
Expand Down
10 changes: 10 additions & 0 deletions src/test/scenarios/datafactory/configuration/readme.az.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ directive:
set:
group: datafactory


cli:
cli-directive:
# directive on operationGroup
- where:
parameter: factoryName
alias:
- name
- n

```
Original file line number Diff line number Diff line change
Expand Up @@ -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', 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),
Expand All @@ -59,14 +59,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.')
Expand All @@ -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', 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'
Expand All @@ -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', 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.')
14 changes: 9 additions & 5 deletions src/test/scenarios/datafactory/output/src/datafactory/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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='[email protected]',
# 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -51,27 +51,29 @@ 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'
'ce instance. For example, use \'subscriptions/{subscription-id}\' for a subscription, \'subscriptio'
'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.')
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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='[email protected]',
# 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,
Expand Down

0 comments on commit 165e8fd

Please sign in to comment.