knqyf263 / pet

Simple command-line snippet manager
MIT License
4.41k stars 222 forks source link

Add autosync before local change for new and edit commands #307

Open patrik-bartak opened 2 months ago

patrik-bartak commented 2 months ago

Issue #, if available:

57

Description of changes: Currently, snippets are lost when autosync is enabled and snippets are added from different machines. With this change, auto sync is called both before and after a new snippet is added to the local file. This means remote changes will not be overwritten.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

patrik-bartak commented 2 months ago

To keep it simple I just copied the auto sync call before the local file is changed. The only drawback I see is that there are now two printouts. This is fine but might be confusing.

image image image
patrik-bartak commented 2 months ago

Yep I can do that

patrik-bartak commented 2 months ago

I'm new to open source so I'm happy to practice a bit on a smaller project

patrik-bartak commented 2 months ago

Let's say I want to test func AutoSync(file string) that uses a sync Client. I have two options: refactor to make Client an argument, or using a mocking package like gomock. Is this right or am I missing something?

RamiAwar commented 2 months ago

Yes exactly. You need to parametrize these dependencies, then you'll be able to replace them with your mocks. By making Client an argument, you can then bring in our own TestClient and pass that in instead and be able to test the logic without calling a real client! I would've linked a nice article on dependency inversion and injection, but I couldn't find one that wasn't worded in a complicated way, and I think you've got the idea honestly.

RamiAwar commented 1 month ago

@patrik-bartak can i help with anything? are you stuck or something or just haven't had the time?