kowainik / life-sync

🔄 Synchronize personal configs across multiple machines
https://kowainik.github.io/projects/life-sync
Mozilla Public License 2.0
21 stars 3 forks source link

Enhance life add command #64

Open SanchayanMaity opened 4 years ago

SanchayanMaity commented 4 years ago

Currently the "life add" command aborts if a life file is not present and the user is starting fresh but wants to add a dotfiles repository. The "onlyRepo" case in lifeAdd function should be enhanced to handle this.

@vrom911 @chshersh Thoughts on this? Would this be an acceptable addition?

chshersh commented 4 years ago

@SanchayanMaity Could you, please clarify a few more details regarding your use case? How could it be that .life file is not present if you created dotfiles with life init command? life add command assumes that you have properly configured .life.

SanchayanMaity commented 4 years ago

life init aborts in case the dotfile repository already exists which is the case where whatIsLife returns OnlyRepo. In my use case, one would like to use an existing dotfile repo and have it managed with life-sync. So, the two options would be to modify the OnlyRepo case of lifeInit or lifeAdd. lifeAdd seemed like the one which should be modified.

chshersh commented 4 years ago

I think that supporting use-case with the existing dotfiles repo is worth pursuing. I can propose the following solution:

  1. In OnlyRepo case ask interactively what users want to do: create empty .life file or completely initialize repo from the files (for now the code can simply create empty .life which can be populated with life add later) but in long-term it would be cool to implement full-featured initiliation with checking each file for equality.
  2. In life add if .life file is not present, print a message saying that probably life init can help.

Anyway, creating empty .life file is just touch ~/dotfiles/.life. An it looks like improving the verbosity and usefulness of logging messages can be a worthy goal. Not only tell what went wrong, but also tell, how to fix it.

SanchayanMaity commented 4 years ago

From what I understood, .life has to be present in HOME directory only? I did try doing touch .life in HOME directory but in that case it seems TOML parsing fails when calling life add -d dotfiles?

life: Couldnt parse file .life: "Key files not found"
chshersh commented 4 years ago

@SanchayanMaity Hmm, let me think carefully about invariants we want to preserve and how to handle them properly. I don't have an answer at the moment on the best approach here.

Regarding parsing error: looks like that at the moment the minimal valid file is:

files = []
directories = []

After migrating to the latest tomland version and patching codec, it should be possible to handle empty file as well.