|
25 | 25 | from tabulate import tabulate |
26 | 26 | from yaml import dump as yaml_dumps |
27 | 27 | from yaml import full_load as yaml_loads |
| 28 | +from yaml import parser |
28 | 29 |
|
29 | 30 | from ._version import get_versions |
30 | 31 | from .exceptions import NFAPINoCredentials |
@@ -501,7 +502,7 @@ def list(cli): |
501 | 502 | # and the set of configured, desired keys |
502 | 503 | valid_keys = set(matches[0].keys()) & set(cli.args.keys) |
503 | 504 | elif cli.config.general.output == "text": |
504 | | - valid_keys = set(matches[0].keys()) & set(['name','label','organizationShortName','id','edgeRouterAttributes','serviceAttributes','endpointAttributes','status','zitiId','provider','locationCode','ipAddress','region','size','attributes','email']) |
| 505 | + valid_keys = set(matches[0].keys()) & set(['name','label','organizationShortName','id','edgeRouterAttributes','serviceAttributes','endpointAttributes','status','zitiId','provider','locationCode','ipAddress','region','size','attributes','email','productVersion']) |
505 | 506 |
|
506 | 507 | if valid_keys: |
507 | 508 | cli.log.debug("valid keys: %s", str(valid_keys)) |
@@ -716,18 +717,30 @@ def edit_object_as_yaml(edit: object): |
716 | 717 | |
717 | 718 | :param obj input: a deserialized (object) to edit and return as yaml |
718 | 719 | """ |
| 720 | + if cli.args.yes: |
| 721 | + return edit |
719 | 722 | EDITOR = os.environ.get('NETFOUNDRY_EDITOR',os.environ.get('EDITOR','vim')) |
720 | | - yaml_dumps(edit, default_flow_style=False) |
721 | 723 | with tempfile.NamedTemporaryFile(suffix=".yml") as tf: |
722 | | - tf.write(yaml_dumps(edit, default_flow_style=False).encode()) |
| 724 | + tf.write(yaml_dumps(edit, default_flow_style=False)) |
723 | 725 | tf.flush() |
724 | 726 | return_code = call(EDITOR.split()+[tf.name]) |
725 | 727 |
|
726 | 728 | tf.seek(0) |
727 | 729 | edited = tf.read() |
728 | 730 | if return_code == 0: |
729 | | - edited_object = yaml_loads(edited) |
730 | | - return edited_object |
| 731 | + try: |
| 732 | + edited_object = yaml_loads(edited) |
| 733 | + except parser.ParserError as e: |
| 734 | + cli.log.error("invalid YAML or JSON: %s", e) |
| 735 | + with tempfile.NamedTemporaryFile(suffix=".yml") as tf: |
| 736 | + tf.write(edited) |
| 737 | + cli.log.warn("your buffer was saved in %s and you may edit and redirect to the same command as stdin or --file", tf.name) |
| 738 | + exit(1) |
| 739 | + except Exception as e: |
| 740 | + cli.log.error("unknown error in %s", e) |
| 741 | + exit(1) |
| 742 | + else: |
| 743 | + return edited_object |
731 | 744 | else: |
732 | 745 | cli.log.debug("error editing temporary file") |
733 | 746 | exit(1) |
|
0 commit comments