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

Add new line if not present in the clients.yml file #145

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ponytojas
Copy link

@ponytojas ponytojas commented Sep 12, 2024

Add newline before appending to config/clients.yml
This change ensures that a newline is added before appending new content to the config/clients.yml file. It addresses the following scenarios:
1. If the file already ends with a newline, no additional newline is added.
2. If the file doesn't end with a newline, a newline is inserted before the new content.
This modification improves the reliability of the configuration file generation process by preventing potential formatting issues or unintended merging of content.

EDIT

I added also a check for existing configuration in the clients.yml file based on the client_name and client_id to avoid duplicates

EDIT 2

After careful consideration, I've decided to refactor and rewrite a significant portion of the code while maintaining the core logic. This refactoring was necessary to properly handle several edge cases that were not initially accounted for in the original implementation.

Unfortunately, due to the new manipulations performed by the code, I had to introduce a dependency:

  • yq: A lightweight command-line YAML processor.

The code checks for the existence of a newline at the end of the file, but now in addition to the newline check, the code verifies if a client_id or client_name already exists in the file. If found, the existing entry is modified with the new data instead of adding a duplicate entry.

This enhancement allows for more robust handling of clients, preventing duplicates and ensuring that existing entries are properly updated when new information is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant