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 add/import subcommand #142

Open
AstraLuma opened this issue Jul 4, 2020 · 6 comments
Open

Add add/import subcommand #142

AstraLuma opened this issue Jul 4, 2020 · 6 comments

Comments

@AstraLuma
Copy link

Add a command to quickly & easily import a file into an emanate repo. (Avoiding the dance.)

@duckinator
Copy link
Owner

@astronouth7303 I really like this idea, but there's some small details to work out.

First, is this (approximately) the dance you're referring to?

$ mv ~/some-file ~/dotfiles
$ cd ~/dotfiles
~/dotfiles$ emanate

Second, how clever should it try to be?

I think a crude proof-of-concept could be to just have a command do something along the lines of this in emanate.cli:

# NOTE: This code is untested and incomplete, but I think is in the right ballpark for a proof-of-concept.

# In `emanate.Emanate`:
def add(file): # Can't be called `import` to avoid angering the snek, so I guess we're going with `add`?
    file_path = Path(file).expanduser().absolute() # or something like that
    dest_path = str(file_path).sub(self.config.source, self.dest) # possibly?
    file_path.rename(dest_path) # rename won't clobber existing files afaik.

Then, in emanate.cli, basically map emanate add <file> => Emanate(...).add("<file>")

@AstraLuma
Copy link
Author

Something to that effect? Assuming you have some knowledge about where the source was

@AstraLuma
Copy link
Author

Oh, and directories are Fun

@duckinator
Copy link
Owner

duckinator commented Jul 4, 2020

When you run emanate, it has a --source <source directory> flag for all subcommands. If you don't specify it, it defaults to the cwd.

So with something like that code above, you could just do emanate --source /path/to/srcdir add <file>.

But yeah, directories would be... interesting. EDIT: actually I think the idea above should handle directories fine.

@nbraud
Copy link
Collaborator

nbraud commented Apr 10, 2021

I think we should (try to?) ensure the operation is atomic (i.e. either everything got moved and symlinked to the Emanate repo, or nothing changed and we returned with an error)

@duckinator
Copy link
Owner

duckinator commented Apr 13, 2021

I agree. I'm pretty hesitant to add this if it's not atomic, or damn close to it.

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

No branches or pull requests

3 participants