Refactor -o option to simplify code
[osm/osmclient.git] / osmclient / cli_commands / ns.py
index 441ae05..75054fe 100755 (executable)
@@ -38,15 +38,9 @@ logger = logging.getLogger("osmclient")
     is_flag=True,
     help="get more details of the NS (project, vim, deployment status, configuration status.",
 )
-@click.option(
-    "-o",
-    default="table",
-    is_eager=True,
-    callback=print_output.validate_command_output,
-    help="adapt the output as table, yaml, csv, json, jsonpath",
-)
+@print_output.output_option
 @click.pass_context
-def ns_list(ctx, filter, long, o):
+def ns_list(ctx, filter, long, output):
     """list all NS instances
 
     \b
@@ -302,9 +296,7 @@ def ns_list(ctx, filter, long, o):
                     utils.wrap_text(text=error_details, width=40),
                 ]
             )
-    table.align = "l"
-    # print(table)
-    print_output.print_output(o, table.field_names, table._rows)
+    print_output.print_output(output, table.field_names, table._rows)
     print('To get the history of all operations over a NS, run "osm ns-op-list NS_ID"')
     print(
         'For more details on the current operation, run "osm ns-op-show OPERATION_ID"'
@@ -319,15 +311,9 @@ def ns_list(ctx, filter, long, o):
     multiple=True,
     help="restricts the information to the fields in the filter",
 )
-@click.option(
-    "-o",
-    default="table",
-    is_eager=True,
-    callback=print_output.validate_command_output,
-    help="adapt the output as table, yaml, csv, json, jsonpath",
-)
+@print_output.output_option
 @click.pass_context
-def ns_show(ctx, name, literal, filter, o):
+def ns_show(ctx, name, literal, filter, output):
     """shows the info of a NS instance
 
     NAME: name or ID of the NS instance
@@ -352,9 +338,7 @@ def ns_show(ctx, name, literal, filter, o):
         for k, v in list(nsr_optdata.items()):
             if not filter or k in filter:
                 table.add_row([k, utils.wrap_text(json.dumps(v, indent=2), width=100)])
-    table.align = "l"
-    print_output.print_output(o, table.field_names, table._rows)
-    # print(table)
+    print_output.print_output(output, table.field_names, table._rows)
 
 
 @click.command(name="ns-create", short_help="creates a new Network Service instance")