copier icon indicating copy to clipboard operation
copier copied to clipboard

feature: access `dst_path` in question context?

Open tlambert03 opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe.

I'd like to be able to provide a default project name, based on the name of the destination path that the user provided on the cli

This looks a lot like the discussion in #20 ... but that was closed, and it's not entirely clear to me whether/how the intended goal was achieved.

Describe the solution you'd like I'd like to be able to use something like this, to initialize a value based on the command line dest path arguments

project_name:
  help: Name of your project
  default: "{{ dst_path | basename }}"

Describe alternatives you've considered

I've considered using the context hook extensions to hack at sys.argv

Additional context

tlambert03 avatar Mar 22 '23 20:03 tlambert03

I’m afraid it’s currently not possible to access the destination path in the questionnaire.

A question only has access to answers to other questions:

https://github.com/copier-org/copier/blob/42a34bf568a8f105701f0869d3afe7fdc4a72c39/copier/main.py#L363-L368

Additional variables such as _folder_name, which is what you’re interested in, are currently only available in the render context after the questionnaire has been completed:

https://github.com/copier-org/copier/blob/42a34bf568a8f105701f0869d3afe7fdc4a72c39/copier/main.py#L252-L259

But I believe it‘s possible to extend Copier to provide at least a subset of these variables also to the render context of a question.

I think it’s an interesting use case.

WDYT, @yajo?

sisp avatar Mar 22 '23 21:03 sisp

Yes, makes sense. At least for the things that are known at that point.

yajo avatar Apr 07 '23 07:04 yajo