Skip to content

Commit

Permalink
Apply prefilled values
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-hilden committed Sep 12, 2021
1 parent 1bed4f0 commit 48106a5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/mold/cli/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .. import Tool, Interface, hook
from ..template import write, render, undeclared_vars
from ..config import gather_categories
from ..config import gather_categories, load_prefilled
from .configure import (
concretise_config, select_config, select_one, print_choices, tool_or_category_repr
)
Expand Down Expand Up @@ -61,11 +61,12 @@ def generate(name: str = None, add: bool = False):

check_dependencies(tools)
faces = gather_interfaces(tools)
prefilled = load_prefilled()

print('\nConfigure project:')
for face in faces:
for question in face.questions:
question.response = dialog(question.prompt)
question.response = prefilled.get(question.id) or dialog(question.prompt)

for face in faces:
face.post_dialog()
Expand Down
8 changes: 3 additions & 5 deletions src/mold/cli/prefill.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
"""Mold prefill values."""
import json

from ..config import user_configs
from ..config import load_prefilled, prefill_file
from ..hook import _domains
from .generate import gather_interfaces, dialog

prefill_file = user_configs / 'prefill.json'


def prefill_show():
"""Show prefilled values."""
if not prefill_file.exists():
values = load_prefilled()
if not values:
print('No prefilled values!')
return

values = json.loads(prefill_file.read_text())
for k, v in values.items():
print(f'{k}: {v}')

Expand Down
11 changes: 10 additions & 1 deletion src/mold/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Mold configuration files."""
"""Mold configuration and prefill files."""
import json

from collections import defaultdict
Expand All @@ -10,6 +10,7 @@
user_configs = Path().home() / '.mold'
builtin_configs = Path(__file__).parent / 'configs'
config_suffix = '.config.json'
prefill_file = user_configs / 'prefill.json'


@dataclass
Expand Down Expand Up @@ -100,3 +101,11 @@ def gather_categories(tools: List[Tool]) -> Dict[Optional[Category], List[Tool]]
for tool in tools:
category_tools[tool.category].append(tool)
return category_tools


def load_prefilled():
"""Load prefilled values."""
if not prefill_file.exists():
return {}

return json.loads(prefill_file.read_text())
3 changes: 1 addition & 2 deletions src/mold/plugins/tools/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from ...face.todo import Accepts as TodoVars
from ...face.doc import Accepts as DocVars

_clone_msg = """Clone GitHub repository now?
(Make the repository if you haven't already) Y/[N]: """
_clone_msg = """Clone GitHub repository now (Y/[N]): """


def accept_vars():
Expand Down

0 comments on commit 48106a5

Please sign in to comment.