Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change to dictionary format #97

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading