зеркало из https://github.com/microsoft/azure-cli.git
Merge branch 'master' of https://github.com/tjprescott/azure-cli into AddResourceShowAndSetCommands
This commit is contained in:
Коммит
b7aeb053ec
5
setup.py
5
setup.py
|
@ -55,11 +55,12 @@ CLASSIFIERS = [
|
|||
]
|
||||
|
||||
DEPENDENCIES = [
|
||||
'adal==0.2.0', #from internal index server.
|
||||
'applicationinsights',
|
||||
'azure==2.0.0rc1',
|
||||
'six',
|
||||
'jmespath',
|
||||
'adal==0.2.0' #from internal index server.
|
||||
'pyyaml',
|
||||
'six',
|
||||
]
|
||||
|
||||
with open('README.rst', 'r', encoding='utf-8') as f:
|
||||
|
|
|
@ -42,7 +42,7 @@ def print_description_list(help_files, out=sys.stdout):
|
|||
_out = out
|
||||
|
||||
indent = 1
|
||||
max_name_length = max(len(f.name) for f in help_files)
|
||||
max_name_length = max(len(f.name) for f in help_files) if help_files else 0
|
||||
for help_file in help_files:
|
||||
_print_indent('{0}{1}{2}'.format(help_file.name,
|
||||
_get_column_indent(help_file.name, max_name_length),
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import sys
|
||||
import json
|
||||
import re
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from six import StringIO
|
||||
|
@ -44,13 +45,18 @@ def format_list(obj):
|
|||
lo = ListOutput()
|
||||
return lo.dump(obj_list)
|
||||
|
||||
def format_tsv(obj):
|
||||
obj_list = obj if isinstance(obj, list) else [obj]
|
||||
return TsvOutput.dump(obj_list)
|
||||
|
||||
class OutputProducer(object): #pylint: disable=too-few-public-methods
|
||||
|
||||
format_dict = {
|
||||
'json': format_json,
|
||||
'table': format_table,
|
||||
'text': format_text,
|
||||
'list': format_list
|
||||
'list': format_list,
|
||||
'tsv': format_tsv,
|
||||
}
|
||||
|
||||
KEYS_CAMELCASE_PATTERN = re.compile('(?!^)_([a-zA-Z])')
|
||||
|
@ -230,3 +236,41 @@ class TextOutput(object):
|
|||
io.close()
|
||||
return result
|
||||
|
||||
class TsvOutput(object): #pylint: disable=too-few-public-methods
|
||||
|
||||
@staticmethod
|
||||
def _dump_obj(data, stream):
|
||||
if isinstance(data, list):
|
||||
stream.write(str(len(data)))
|
||||
elif isinstance(data, dict):
|
||||
# We need to print something to avoid mismatching
|
||||
# number of columns if the value is None for some instances
|
||||
# and a dictionary value in other...
|
||||
stream.write('{object}')
|
||||
else:
|
||||
stream.write(data)
|
||||
|
||||
@staticmethod
|
||||
def _dump_row(data, stream):
|
||||
if isinstance(data, dict):
|
||||
separator = ''
|
||||
# Iterate through the items either sorted by key value (if dict) or in the order
|
||||
# they were added (in the cases of an ordered dict) in order to make the output
|
||||
# stable
|
||||
for _, value in data.items() if isinstance(data, OrderedDict) else sorted(data.items()):
|
||||
stream.write(separator)
|
||||
TsvOutput._dump_obj(value, stream)
|
||||
separator = '\t'
|
||||
else:
|
||||
TsvOutput._dump_obj(data, stream)
|
||||
|
||||
@staticmethod
|
||||
def dump(data):
|
||||
io = StringIO()
|
||||
for item in data:
|
||||
TsvOutput._dump_row(item, io)
|
||||
io.write('\n')
|
||||
|
||||
result = io.getvalue()
|
||||
io.close()
|
||||
return result
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import collections
|
||||
|
||||
def register(event_dispatcher):
|
||||
def handle_query_parameter(_, event_data):
|
||||
try:
|
||||
|
@ -10,7 +12,7 @@ def register(event_dispatcher):
|
|||
else:
|
||||
def filter_output(_, event_data):
|
||||
import jmespath
|
||||
event_data['result'] = jmespath.search(query_value, event_data['result'])
|
||||
|
||||
event_data['result'] = jmespath.search(query_value, event_data['result'],
|
||||
jmespath.Options(collections.OrderedDict))
|
||||
event_dispatcher.register(event_dispatcher.FILTER_RESULT, filter_output)
|
||||
event_dispatcher.register(event_dispatcher.REGISTER_GLOBAL_PARAMETERS, handle_query_parameter)
|
||||
|
|
Загрузка…
Ссылка в новой задаче