Skip to content

Commit

Permalink
refactor: change to dictionary format (#97)
Browse files Browse the repository at this point in the history
* updated documentation

* changed sugar.py iteration to adapt to dictionary syntax, aslo corrected documentation and test

* with pre-commit run
  • Loading branch information
joel5vega authored Dec 20, 2023
1 parent 3be70ac commit 028096a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
8 changes: 4 additions & 4 deletions .sugar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 14 additions & 10 deletions src/sugar/sugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 028096a

Please sign in to comment.