From 12584c8cb3766dcab52c8eae2116f515875c16b8 Mon Sep 17 00:00:00 2001 From: Iakov Gan Date: Thu, 2 Nov 2023 07:39:38 +0100 Subject: [PATCH] cli doc enhancements and fixes --- cid/cli.py | 4 +++- cid/common.py | 35 +++++++++++++++++------------------ cid/export.py | 1 + 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/cid/cli.py b/cid/cli.py index 4572a566..961b2c40 100644 --- a/cid/cli.py +++ b/cid/cli.py @@ -111,6 +111,7 @@ def deploy(ctx, **kwargs): \b Command options: + --category TEXT The dashboards category to choose from. Not needed if dashboard-id provided directly --dashboard-id TEXT QuickSight dashboard id (cudos, cost_intelligence_dashboard, kpi_dashboard, ta-organizational-view, trends-dashboard etc) --athena-database TEXT Athena database --athena-workgroup TEXT Athena workgroup @@ -134,7 +135,7 @@ def deploy(ctx, **kwargs): @click.option('-y', '--yes', help='confirm all', is_flag=True, default=False) @cid_command def export(ctx, **kwargs): - """Expot Dashboard + """Export Dashboard \b Command options: @@ -148,6 +149,7 @@ def export(ctx, **kwargs): (definition|template) A method (definition=pull json definition of Analysis OR template=create QuickSight Template) --export-known-datasets (no|yes) If 'yes' the export will include DataSets that are already in resources file. Default = no + --category TEXT The dashboards category. Default = Custom --output A filename (.yaml) """ ctx.obj.export(**kwargs) diff --git a/cid/common.py b/cid/common.py index c7730fce..25a984cb 100644 --- a/cid/common.py +++ b/cid/common.py @@ -308,7 +308,8 @@ def load_resource_file(self, source): with open(source, encoding='utf-8') as file_: resources = yaml.safe_load(file_) except Exception as exc: - raise CidCritical(f'Failed to load resources from {source}.') from exc + logger.warning(f'Failed to load resources from {source}: {exc}') + return self.resources = always_merger.merge(self.resources, resources) def load_catalog(self, catalog_url=None): @@ -385,33 +386,31 @@ def _deploy(self, dashboard_id: str=None, recursive=True, update=False, **kwargs dashboard_id = dashboard_id or get_parameters().get('dashboard-id') if not dashboard_id: + standard_categories = ['Foundational', 'Advanced', 'Additional'] + all_categories = set([f"{dashboard.get('category', 'Custom')}" for dashboard in self.resources.get('dashboards').values()]) + non_standard_categories = [cat for cat in all_categories if cat not in standard_categories] while True: - category_options = ['Foundational', 'Advanced', 'Additional'] + \ - sorted(list(set([ - f"{dashboard.get('category', 'Custom')}" - for k, dashboard in self.resources.get('dashboards').items() - if f"{dashboard.get('category', 'Custom')}" not in ('Foundational', 'Advanced', 'Additional') - ]))) + category_options = standard_categories + sorted(non_standard_categories) category = get_parameter( param_name='category', - message="Please select a category of dashboard to install", + message="Please select a category of dashboard to deploy", choices=category_options, ) - dashboard_options = { - f"[{dashboard.get('dashboardId')}] {dashboard.get('name')}" : dashboard.get('dashboardId') - for k, dashboard in self.resources.get('dashboards').items() - if dashboard.get('category', 'Custom') == category - } + dashboard_options = {} + for dashboard in self.resources.get('dashboards').values(): + if dashboard.get('category', 'Custom') == category: + dashboard_options[f"[{dashboard.get('dashboardId')}] {dashboard.get('name')}"] = dashboard.get('dashboardId') dashboard_options['<<< back'] = '<<< back' dashboard_id = get_parameter( param_name='dashboard-id', - message="Please select dashboard to install", + message="Please select a dashboard to deploy", choices=dashboard_options, ) - if dashboard_id != '<<< back': - break - unset_parameter('category') - unset_parameter('dashboard-id') + if dashboard_id == '<<< back': + unset_parameter('category') + unset_parameter('dashboard-id') + continue + break if not dashboard_id: print('No dashboard selected') diff --git a/cid/export.py b/cid/export.py index b158bdd6..11dab5b9 100644 --- a/cid/export.py +++ b/cid/export.py @@ -262,6 +262,7 @@ def export_analysis(qs, athena): } dashboard_resource['name'] = analysis['Name'] dashboard_resource['dashboardId'] = dashboard_id + dashboard_resource['category'] = get_parameters().get('category', 'Custom') dashboard_export_method = None if get_parameters().get('template-id'):