if want json format results, use command like below:
compare -t compare_template.yaml --theme json
otherwise, print table format results by default:
compare -t compare_template.yaml
Signed-off-by: Lu Kaiyi 2392863668@qq.com --- lib/compare.rb | 4 ++-- lib/compare_matrixes.rb | 10 +++++++--- sbin/compare | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/lib/compare.rb b/lib/compare.rb index f34e239..db264f8 100644 --- a/lib/compare.rb +++ b/lib/compare.rb @@ -96,11 +96,11 @@ end # unit: KB/s #
-def compare_by_template(template) +def compare_by_template(template, options) template_params = load_template(template) groups_matrices = create_groups_matrices(template_params) compare_results = compare_metrics_values(groups_matrices) - show_compare_result(compare_results, template_params) + show_compare_result(compare_results, template_params, options) end
def load_template(template) diff --git a/lib/compare_matrixes.rb b/lib/compare_matrixes.rb index 9bf676f..b7ea5a4 100644 --- a/lib/compare_matrixes.rb +++ b/lib/compare_matrixes.rb @@ -508,11 +508,15 @@ def get_dimensions_combination(dimension_list) dims end
-def show_compare_result(metrics_compare_results, template_params) +def show_compare_result(metrics_compare_results, template_params, options) formatter = FormatEchartData.new(metrics_compare_results, template_params) echart_results = formatter.format_for_echart - table_results = FormatTableData.new(echart_results) - table_results.show_table + if options[:theme] == 'json' + print JSON.pretty_generate(echart_results) + else + table_results = FormatTableData.new(echart_results) + table_results.show_table + end end
# Format Fields diff --git a/sbin/compare b/sbin/compare index c13ec1a..e8d1ac4 100755 --- a/sbin/compare +++ b/sbin/compare @@ -67,7 +67,7 @@ opt_parser.parse!(argv) options = { theme: colorful } if colorful
if template - compare_by_template(template) + compare_by_template(template, options) elsif is_group compare_group(argv, dimensions, options) else