Browse Source

added the ability for a check to have multiple returns (#27)

Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
Kevin Carter 2 years ago
parent
commit
b2b2f8e7b5
1 changed files with 18 additions and 6 deletions
  1. 18
    6
      monitorstack/cli.py

+ 18
- 6
monitorstack/cli.py View File

@@ -98,14 +98,16 @@ VALID_OUTPUT_FORMATS = [
98 98
 )
99 99
 @click.option('-v', '--verbose', is_flag=True, help='Enables verbose mode.')
100 100
 @pass_context
101
-def cli(ctx, output_format, verbose):
101
+def cli(*args, **kwargs):
102 102
     """A complex command line interface."""
103
-    ctx.verbose = verbose
104
-    pass
103
+    try:
104
+        args[0].verbose = kwargs.get('verbose', False)
105
+    except IndexError:  # pragma: no cover
106
+        pass
105 107
 
106 108
 
107 109
 @cli.resultcallback(replace=True)
108
-def process_result(result, output_format, verbose):
110
+def process_result(results, output_format, **kwargs):
109 111
     """Render the output into the proper format."""
110 112
     module_name = 'monitorstack.common.formatters'
111 113
     method_name = 'write_{}'.format(output_format.replace('-', '_'))
@@ -113,8 +115,18 @@ def process_result(result, output_format, verbose):
113 115
         importlib.import_module(module_name),
114 116
         method_name
115 117
     )
116
-    output_formatter(result)
117
-    sys.exit(result['exit_code'])
118
+
119
+    # Force the output formatter into a list
120
+    if not isinstance(results, list):  # pragma: no cover
121
+        results = [results]
122
+
123
+    exit_code = 0
124
+    for result in results:
125
+        output_formatter(result)
126
+        if result['exit_code'] != 0:
127
+            exit_code = result['exit_code']
128
+    else:
129
+        sys.exit(exit_code)
118 130
 
119 131
 
120 132
 if __name__ == '__main__':

Loading…
Cancel
Save