graphprotocol / graph-tooling

Monorepo for various tools used by subgraph developers.
https://thegraph.com/docs
Apache License 2.0
392 stars 210 forks source link

Add prompt for existing directory in `init` flow #1750

Closed 0237h closed 3 weeks ago

0237h commented 1 month ago

If the user is choosing an existing directory for creating a new subgraph, ask for confirmation. If the answer is negative, abort the process.

Closes #1370

changeset-bot[bot] commented 1 month ago

🦋 Changeset detected

Latest commit: e79d45cf383e8ce5d0ef4d4f617bad808dc8b808

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------------------ | ----- | | @graphprotocol/graph-cli | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

YaroShkvorets commented 1 month ago

After confirming that I want to use the existing directory it proceeds but then fails with Error: Directory or file "weth" already exists. Should probably overwrite?

image
0237h commented 4 weeks ago

After confirming that I want to use the existing directory it proceeds but then fails with Error: Directory or file "weth" already exists. Should probably overwrite?

Fixed in #4eaf6a2 thanks.

Also fixed when using --from-example flag.

YaroShkvorets commented 4 weeks ago

@0237h I think we should delete all files from the directory. Othewise we could be mixing different projects and/or committing a bunch of unrelated files into subgraph repository, which is not great.

Unless you can think of a scenario where we would want to keep any old files in the directory we are overwriting.

0237h commented 4 weeks ago

I would argue that it could be more dangerous deleting files.

Right now, if you're not careful with the prompt, you'll end up overwriting/adding new files which isn't big deal. If we add deletion, one mistake and you could get files removed (any files).

Also there might be some use cases where you have ABIs in a subfolder that you might want to keep ? Not entirely sure but in any case I would avoid deleting files and letting the user do it. Otherwise they should use a new directory, not existing one.

YaroShkvorets commented 4 weeks ago

Yes, I agree about deleting being dangerous. Although I'm still having hard time picturing when it would be useful to keep existing files in your repo.

The ideal flow would probably be checking if directory exists right after the prompt and requiring to enter the different directory name. We can still keep "overwrite yes/no" prompt when generating the project. Can be a separate issue if that's too much work.