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 the ability to customise the prompt for a question #680

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: Add a prompt attribute to questions
  • Loading branch information
pfmoore committed May 25, 2022
commit dcc4d1f85cf42364832b34b02fdb63cb914b271d
9 changes: 8 additions & 1 deletion copier/user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class Question:
Additional text printed to the user, explaining the purpose of
this question. Can be templated.

prompt:
The prompt used when asking the question. Can be templated.

multiline:
Indicates if the question should allow multiline input. Defaults
to `True` for JSON and YAML questions, and to `False` otherwise.
Expand Down Expand Up @@ -188,6 +191,7 @@ class Question:
choices: Union[Dict[Any, Any], List[Any]] = field(default_factory=list)
default: Any = None
help: str = ""
prompt: str = ""
ask_user: bool = False
multiline: Union[str, bool] = False
placeholder: str = ""
Expand Down Expand Up @@ -293,7 +297,10 @@ def get_message(self) -> str:
if self.help:
rendered_help = self.render_value(self.help)
message = force_str_end(rendered_help)
message += f"{self.var_name}? Format: {self.get_type_name()}"
if self.prompt:
message += self.render_value(self.prompt)
else:
message += f"{self.var_name}? Format: {self.get_type_name()}"
return message

def get_placeholder(self) -> str:
Expand Down