From 646f871e31814510c99b33ba2e235203e20f9942 Mon Sep 17 00:00:00 2001 From: Jan van Mansum Date: Tue, 28 Nov 2023 11:19:20 +0100 Subject: [PATCH] print as JSON --- .../datastation_component_versions.py | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/datastation/datastation_component_versions.py b/src/datastation/datastation_component_versions.py index 0fe9c70..906928a 100644 --- a/src/datastation/datastation_component_versions.py +++ b/src/datastation/datastation_component_versions.py @@ -1,3 +1,5 @@ +import argparse + from rich.console import Console from rich.table import Table @@ -8,19 +10,30 @@ def main(): config = init() + + parser = argparse.ArgumentParser( + description='Gets the version of all Data Station components in this installation.') + parser.add_argument('--json', dest='json', action='store_true', help='Output as JSON') + args = parser.parse_args() + components = get_rpm_versions(config['version_info']['dans_rpm_module_prefix']) dataverse_version = get_dataverse_version(config['version_info']['dataverse_application_path']) dataverse_build_number = get_dataverse_build_number(config['version_info']['dataverse_application_path']) components['dataverse'] = f'{dataverse_version} build {dataverse_build_number}' payara_version = get_payara_version(config['version_info']['payara_install_path']) components['payara'] = payara_version - table = Table(title="Data Station Component Versions") - table.add_column("Component") - table.add_column("Version") - for component in components: - table.add_row(component, components[component]) - console = Console() - console.print(table) + + if args.json: + print(components) + return + else: + table = Table(title="Data Station Component Versions") + table.add_column("Component") + table.add_column("Version") + for component in components: + table.add_row(component, components[component]) + console = Console() + console.print(table) if __name__ == '__main__':