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

Fail fast on directory already exists #821

Open
ssteinerx opened this issue Sep 8, 2016 · 7 comments
Open

Fail fast on directory already exists #821

ssteinerx opened this issue Sep 8, 2016 · 7 comments
Labels
enhancement This issue/PR relates to a feature request.

Comments

@ssteinerx
Copy link

  • Cookiecutter version: 1.4.0
  • Template project url: local
  • Python version: 2.7
  • Operating System: 10.10.6

Description:

If the destination directory already exists (based on the project name), cookiecutter fails after all questions are asked.

What I've run:

cookiecutter, fill out name of existing directory should fail as soon as it can detect, not after answering all of the questions.

@hackebrot
Copy link
Member

I see how checking the target directory while prompting would improve the user experience.

Do you want to create a PR, @ssteinerx?

@hackebrot hackebrot added the enhancement This issue/PR relates to a feature request. label Dec 30, 2016
@ssteinerx
Copy link
Author

Unfortunately, prompt.prompt_for_config doesn't know anything about what is being asked; it just iterates through the given context and collects the specified information.

The 'context' is just the parsed cookiecutter.json, so there's no information there vis-à-vis validation of inputs. The json just holds the prompts and default values.

Special-casing this one thing by name could be done but ick.

Without major rearrangement of cookiecutter.json to have validation hooks etc. (and essentially rewriting all the associated routines), or gluing on some special-case side-car validation gizmo onto prompt_for_config, there's no obvious/non-icky way of handling this with the current architecture.

@hackebrot
Copy link
Member

Thanks for investigating, @ssteinerx! 🙇

Sounds like another feature for #848 to me.

@ssteinerx
Copy link
Author

@hackebrot Yes, I didn't have time to read the spec, but this type of fail-fast should be built in somehow.

@theodesp
Copy link

theodesp commented Aug 9, 2017

I see that we can decorate the prompt_for_config with something like a context aware prompt that will trigger extra actions when detecting special keys.

For example if it detects a key named project_slug will trigger a callback to check if the folder exists.

I think it's possible to do with out breaking changes. That will be a chance to refactor the prompt.py

@ssteinerx
Copy link
Author

@theodesp I haven't looked at this in quite a while (like 8 months!), but I remember thinking that I'd want to have a way of indicating that prompt invokes action-type validator action-type-validator e.g.:

I haven't got time to look right this second, but I vaguely remember wanting something like:

prompt("Create the docs directory?", action_type="create-directory", validator="prompt-overwrite-if-exists-or-exit")

@theodesp
Copy link

theodesp commented Aug 9, 2017

Yes thats another good idea. As you said prompt.prompt_for_config doesn't know anything about what is being asked: So we need to keep the existing functionality. Maybe if we pass a map of keys to validators as a parameter that will get called if the particular key was prompted and filled as I dont see any support for validation in click prompt http://click.pocoo.org/5/api/#click.prompt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue/PR relates to a feature request.
Projects
None yet
Development

No branches or pull requests

3 participants