Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified az
100755 → 100644
Empty file.
13 changes: 0 additions & 13 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@
<Compile Include="azure\cli\commands\_command_creation.py" />
<Compile Include="azure\cli\commands\__init__.py" />
<Compile Include="azure\cli\main.py" />
<Compile Include="azure\cli\tests\command_specs\test_spec_network.py" />
<Compile Include="azure\cli\tests\command_specs\test_spec_resource.py" />
<Compile Include="azure\cli\tests\command_specs\test_spec_vm.py" />
<Compile Include="azure\cli\tests\command_specs\__init__.py" />
<Compile Include="azure\cli\tests\test_argparse.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="azure\cli\tests\test_autocommand.py" />
<Compile Include="azure\cli\tests\test_commands.py" />
<Compile Include="azure\cli\tests\test_connection_verify.py" />
<Compile Include="azure\cli\tests\test_output.py" />
<Compile Include="azure\cli\_locale.py" />
Expand All @@ -62,8 +57,6 @@
<Folder Include="azure\cli" />
<Folder Include="azure\cli\commands" />
<Folder Include="azure\cli\tests\" />
<Folder Include="azure\cli\tests\command_specs\" />
<Folder Include="azure\cli\tests\recordings\" />
</ItemGroup>
<ItemGroup>
<Interpreter Include="..\env\">
Expand All @@ -78,12 +71,6 @@
<Architecture>X86</Architecture>
</Interpreter>
</ItemGroup>
<ItemGroup>
<Content Include="azure\cli\tests\recordings\command_specs.test_spec_network.test_network_usage_list.yaml" />
<Content Include="azure\cli\tests\recordings\command_specs.test_spec_resource.test_resource_group_list.yaml" />
<Content Include="azure\cli\tests\recordings\command_specs.test_spec_vm.test_vm_usage_list_westus.yaml" />
<Content Include="azure\cli\tests\recordings\README.rst" />
</ItemGroup>
<Import Project="$(PtvsTargetsFile)" Condition="Exists($(PtvsTargetsFile))" />
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" Condition="!Exists($(PtvsTargetsFile))" />
</Project>
5 changes: 3 additions & 2 deletions src/azure/cli/_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def add_command(self,
m['$args'] = []
m['$kwargs'] = kw = {}
m['$argdoc'] = ad = []
for spec, desc, req in args or []:
for spec, desc, req, target in args or []:
if not any(spec.startswith(p) for p in ARG_PREFIXES):
m['$args'].append(spec.strip('<> '))
ad.append((spec, desc, req))
Expand All @@ -123,7 +123,8 @@ def add_command(self,
v = True
else:
v = aliases.pop().strip('<> ')
target, _ = _read_arg(aliases[0])
if not target:
target, _ = _read_arg(aliases[0])
kw.update({_read_arg(a)[0]: (target, v, req, aliases) for a in aliases})
ad.append(('/'.join(aliases), desc, req))

Expand Down
4 changes: 2 additions & 2 deletions src/azure/cli/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def add_description(handler):
return handler
return add_description

def option(spec, description_text=None, required=False):
def option(spec, description_text=None, required=False, target=None):
def add_option(handler):
_COMMANDS.setdefault(handler, {}).setdefault('args', []) \
.append((spec, description_text, required))
.append((spec, description_text, required, target))
logger.debug('Added option "%s" to %s', spec, handler)
return handler
return add_option
Expand Down
42 changes: 30 additions & 12 deletions src/azure/cli/commands/_auto_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
from azure.cli._argparse import IncorrectUsageError
from ..commands import command, description, option


EXCLUDED_PARAMS = frozenset(['self', 'raw', 'custom_headers', 'operation_config'])
GLOBALPARAMALIASES = {
'resource_group_name': '--resourcegroup --rg <resourcegroupname>'
}



class LongRunningOperation(object): #pylint: disable=too-few-public-methods

progress_file = sys.stderr
Expand Down Expand Up @@ -41,13 +49,24 @@ def _decorate_command(name, func):
def _decorate_description(desc, func):
return description(desc)(func)

def _decorate_option(spec, descr, func):
return option(spec, descr)(func)
def _decorate_option(spec, descr, target, func):
return option(spec, descr, target=target)(func)

def _get_member(obj, path):
"""Recursively walk down the dot-separated path
to get child item.

def _make_func(client_factory, member_name, return_type_or_func, unbound_func):
Ex. a.b.c would get the property 'c' of property 'b' of the
object a
"""
for segment in path.split('.'):
obj = getattr(obj, segment)
return obj

def _make_func(client_factory, member_path, return_type_or_func, unbound_func):
def call_client(args, unexpected): #pylint: disable=unused-argument
client = client_factory()
ops_instance = getattr(client, member_name)
ops_instance = _get_member(client, member_path)
try:
result = unbound_func(ops_instance, **args)
if not return_type_or_func:
Expand All @@ -65,7 +84,6 @@ def call_client(args, unexpected): #pylint: disable=unused-argument
message = getattr(client_exception, 'message', client_exception)
print(message, file=sys.stderr)


return call_client

def _option_description(operation, arg):
Expand All @@ -76,13 +94,12 @@ def _option_description(operation, arg):
return ' '.join(l.split(':')[-1] for l in inspect.getdoc(operation).splitlines()
if l.startswith(':param') and arg + ':' in l)

EXCLUDED_PARAMS = frozenset(['self', 'raw', 'custom_headers', 'operation_config'])

def build_operation(package_name, resource_type, member_name, client_type, operations):
def build_operation(command_name, member_path, client_type, operations, #pylint: disable=dangerous-default-value
paramaliases=GLOBALPARAMALIASES):
for operation, return_type_name in operations:
opname = operation.__name__.replace('_', '-')
func = _make_func(client_type, member_name, return_type_name, operation)
func = _decorate_command(' '.join([package_name, resource_type, opname]), func)
func = _make_func(client_type, member_path, return_type_name, operation)
func = _decorate_command(' '.join([command_name, opname]), func)

args = []
try:
Expand All @@ -94,5 +111,6 @@ def build_operation(package_name, resource_type, member_name, client_type, opera
args = sig.args

for arg in [a for a in args if not a in EXCLUDED_PARAMS]:
spec = '--%s <%s>' % (arg, arg)
func = _decorate_option(spec, _option_description(operation, arg), func=func)
spec = paramaliases.get(arg, '--%s <%s>' % (arg, arg))
func = _decorate_option(spec, _option_description(operation, arg),
target=arg, func=func)
Loading