diff --git a/.sugar.yaml b/.sugar.yaml index 1a962bc..c49716b 100644 --- a/.sugar.yaml +++ b/.sugar.yaml @@ -5,7 +5,7 @@ defaults: group: {{ env.KXGR_GROUP }} project-name: sugar-{{ env.KXGR_PROJECT_NAME }} groups: - - name: group1 + group1: project-name: project1 # optional compose-path: tests/containers/group1/compose.yaml env-file: .env @@ -16,7 +16,7 @@ groups: - name: service1-2 - name: service1-3 - - name: group2 + group2: project-name: null # optional compose-path: tests/containers/group2/compose.yaml env-file: .env @@ -26,7 +26,7 @@ groups: - name: service2-1 - name: service2-2 - - name: group-mix + group-mix: project-name: null # optional compose-path: - tests/containers/group1/compose.yaml @@ -40,7 +40,7 @@ groups: - name: service2-1 - name: service2-2 - - name: group-defaults + group-defaults: compose-path: - tests/containers/group1/compose.yaml env-file: .env diff --git a/docs/index.md b/docs/index.md index 277017d..95e8536 100644 --- a/docs/index.md +++ b/docs/index.md @@ -77,7 +77,7 @@ compose-app: docker-compose default: group: {{ "{{ env.ENV }}" }} groups: - - name: group1 + group1: project-name: project1 compose-path: containers/tests/group1/compose.yaml env-file: .env @@ -89,7 +89,7 @@ groups: - name: service1 - name: service2 - name: service3 - - name: group2 + group2: project-name: null compose-path: containers/tests/group2/compose.yaml env-file: .env diff --git a/src/sugar/sugar.py b/src/sugar/sugar.py index f48285b..b718ec4 100644 --- a/src/sugar/sugar.py +++ b/src/sugar/sugar.py @@ -129,26 +129,30 @@ def _filter_service_group(self): "group configuration weren't defined.", KxgrErrorType.KXGR_INVALID_PARAMETER, ) - group_name = default_group + selected_group_name = default_group else: - group_name = self.args.get('service_group') + selected_group_name = self.args.get('service_group') default_project_name = self.defaults.get('project-name') - for g in groups: - if g['name'] == group_name: - if default_project_name and 'project-name' not in g: + for group_name, group_data in groups.items(): + if group_name == selected_group_name: + if default_project_name and 'project-name' not in group_data: # just use default value if "project-name" is not set - g['project-name'] = default_project_name - if not g.get('services', {}).get('default'): + group_data['project-name'] = default_project_name + if not group_data.get('services', {}).get('default'): # if default is not given or it is empty or null, # use as default all the services available default_services = [ service['name'] - for service in g.get('services', {}).get('available') + for service in group_data.get('services', {}).get( + 'available' + ) ] - g['services']['default'] = ','.join(default_services) - self.service_group = g + group_data['services']['default'] = ','.join( + default_services + ) + self.service_group = group_data return KxgrLogs.raise_error(