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

ARIA-148 CLI display commands #107

Merged
merged 1 commit into from
May 11, 2017
Merged

ARIA-148 CLI display commands #107

merged 1 commit into from
May 11, 2017

Conversation

tliron
Copy link
Contributor

@tliron tliron commented Apr 20, 2017

Also includes some typo fixes for the CLI.

@asfbot
Copy link

asfbot commented Apr 20, 2017

Can one of the admins verify this patch?

@asfgit asfgit force-pushed the ARIA-148-extra-cli-commands branch from cd5f233 to cf08b4b Compare April 20, 2017 23:03
@hubot hubot deleted the ARIA-148-extra-cli-commands branch April 28, 2017 17:09
@hubot hubot restored the ARIA-148-extra-cli-commands branch April 28, 2017 22:05
@@ -47,3 +47,8 @@
SORT_BY = "Key for sorting the list"
DESCENDING = "Sort list in descending order [default: False]"
JSON_OUTPUT = "Output logs in a consumable JSON format"

DISPLAY_JSON = "Display in JSON format"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets merge this with JSON_OUTPUT,
the latter is a good name, and simply have it as "Format the output as JSON"

@@ -325,6 +325,30 @@ def __init__(self):
default=defaults.SERVICE_TEMPLATE_FILENAME,
help=helptexts.SERVICE_TEMPLATE_FILENAME)

self.display_json = click.option(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge this with the other JSON one

is_flag=True,
help=helptexts.DISPLAY_JSON)

self.display_yaml = click.option(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yaml_output?

logger.info('Displaying service {0}...'.format(service_name))
service = model_storage.service.get_by_name(service_name)
consumption.ConsumptionContext()
if graph:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General reminder that none of the methods below are standard for the CLI
Fine for now, but keep https://issues.apache.org/jira/browse/ARIA-183 in mind

@aria.options.display_graph
@aria.pass_model_storage
@aria.pass_logger
def display(service_name, model_storage, json, yaml, graph, logger):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking that model_storage should probably sit after graph, before logger

@aria.options.display_types
@aria.pass_model_storage
@aria.pass_logger
def display(service_template_name, model_storage, json, yaml, types, logger):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having both display and show is confusing :/
I agree however that it doesn't make sense to make this command into a mere flag of show as they're very different.
I'm generally ok with this as is, but Maxim wanted me to suggest aria parse service/service-template as an option as well. I'll leave it for your consideration :)

@asfgit asfgit force-pushed the ARIA-148-extra-cli-commands branch 4 times, most recently from 7442a76 to 7e75948 Compare May 9, 2017 21:03
@@ -85,7 +85,7 @@ def get_values_per_column(column, row_data):

return val
else:
return defaults[column]
return defaults.get(column) if defaults is not None else None
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should instead have a defaults = defaults or {} before calling the nested method

service = model_storage.service.get_by_name(service_name)

if json or yaml:
all = True
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd rename the flag, it's both unclear and a python keyword. show_all or all_info might be better.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i actually didnt mean the flag but only the variables etc.,
although now that i think of it it might also be better to change the flag, as it might be confusing i.e. users might think it will show all service-templates or so..?
in any case what matters to me more is the variables, the flag can still be all to the user, but the "destination" of the variable (configurable in aria.py) should be renamed.

service = model_storage.service.get_by_name(service_name)

if json or yaml:
all = True
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i actually didnt mean the flag but only the variables etc.,
although now that i think of it it might also be better to change the flag, as it might be confusing i.e. users might think it will show all service-templates or so..?
in any case what matters to me more is the variables, the flag can still be all to the user, but the "destination" of the variable (configurable in aria.py) should be renamed.

logger.info('Existing services:')
for service in service_template.services:
logger.info('\t{0}'.format(service.name))
if json or yaml:
Copy link

@ran-z ran-z May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm a bit confused by this. so yaml, json, and all all mean all,
and json and yaml can be used simulatniously but only json will get printed.

Re the latter problem, please have a look at aria.py for how to make flags mutually-exclusive.
re the former, it might be better to also have the all flag as mutually-exclusive with the other two, (or that possibly using either json or yaml requires the all flag as well..?)

@asfgit asfgit force-pushed the ARIA-148-extra-cli-commands branch 2 times, most recently from 990a792 to 8219354 Compare May 11, 2017 02:01
'--full',
'mode',
is_flag=True,
flag_value='full',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I don't like this approach as much at the previous one.
It seems like it simplifies the code a bit but makes things somewhat more confusing to the user - specifically the fact that only the last flag of a given "destination" (e.g. mode) takes hold.

If instead you have different destinations for these flags, it'd be easier to inform the user of misuse (even if for some reason the mutually-exclusive mechanism is problematic to use, you can always just manually validate the parameters in the command function itself)

def __init__(self, *args, **kwargs):
self.mutually_exclusive = set(kwargs.pop('mutually_exclusive', []))
self.mutually_exclusive = kwargs.pop('mutually_exclusive', tuple())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change this from a set to another type?

@@ -65,15 +58,33 @@ def __init__(self, *args, **kwargs):
super(MutuallyExclusiveOption, self).__init__(*args, **kwargs)

def handle_parse_result(self, ctx, opts, args):
if self.mutually_exclusive.intersection(opts) and self.name in opts:
if (self.name in opts) and self.mutually_exclusive.keys().intersection(opts):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like mutually_exclusive might be a tuple now, so .keys() would raise an error here.


def mutually_exclusive_option(*param_decls, **attrs):
"""
Makes options mutually exclusive. The decorator must pass a a ``mutually_exclusive`` argument
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a a a a a

options.
"""
def decorator(func):
if 'help' in attrs:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please document this func a bit more?
I'm not sure what are param_decls and attrs in this case, why help is being inspected, and why the internal __click_params__ is accessed directly here.

* Allow "--full" flag to provide a complete dump
* Allow "--json" and "--yaml" flags for dump in those formats
* Support for node graph and type hierarchies
* Some fixes for YAML dump for our custom types
* Also closes ARIA-186: "aria services show" command
@asfgit asfgit force-pushed the ARIA-148-extra-cli-commands branch from 8219354 to fdd57c4 Compare May 11, 2017 17:55
@asfgit asfgit merged commit fdd57c4 into master May 11, 2017
@asfgit asfgit deleted the ARIA-148-extra-cli-commands branch May 14, 2017 19:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants