diff --git a/data/other/config_repository.toml b/data/other/config_repository.toml index 748f7f68a..76c7fa987 100644 --- a/data/other/config_repository.toml +++ b/data/other/config_repository.toml @@ -5,6 +5,7 @@ i18n = "repository_config" name.en = "" [main.main] name.en = "" + optional = false # if method == "tar": question["value"] = False [main.main.description] type = "string" @@ -14,20 +15,18 @@ name.en = "" type = "boolean" yes = true no = false - visible = "creation && is_remote" + visible = "creation" default = "no" [main.main.location] - ask.en = "{is_remote}" type = "string" visible = "creation && is_remote" pattern.regexp = '^([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+((xn--)?[^\W_]{2,})$' - pattern.error = '' # TODO "Please provide a valid domain" + pattern.error = 'location_error' # TODO "Please provide a valid domain" default = "" # FIXME: can't be a domain of this instances ? [main.main.is_f2f] - ask.en = "{is_remote}" help = "" type = "boolean" yes = true diff --git a/src/yunohost/repository.py b/src/yunohost/repository.py index 5f06c5102..ab5e6d62b 100644 --- a/src/yunohost/repository.py +++ b/src/yunohost/repository.py @@ -81,6 +81,10 @@ class BackupRepository(ConfigPanel): #self.method = BackupMethod.get(method, self) + def set__domain(self, question): + # TODO query on domain name .well-known + question.value + def _get_default_values(self): values = super()._get_default_values() values["public_key"] = get_ssh_public_key() diff --git a/src/yunohost/utils/config.py b/src/yunohost/utils/config.py index dedf13621..aafacbdd4 100644 --- a/src/yunohost/utils/config.py +++ b/src/yunohost/utils/config.py @@ -667,7 +667,7 @@ class Question(object): # - we want to keep the previous value # - we want the default value self.value = None - return self.value + return { self.name: self.value } for i in range(5): # Display question if no value filled or if it's a readonly message @@ -689,6 +689,10 @@ class Question(object): # Normalize and validate self.value = self.normalize(self.value, self) self._prevalidate() + # Search for validator in hooks + validator = f"validate__{self.name}" + if validator in self.hooks: + self.hooks[validator](self) except YunohostValidationError as e: # If in interactive cli, re-ask the current question if i < 4 and Moulinette.interface.type == "cli" and os.isatty(1): @@ -703,7 +707,12 @@ class Question(object): self.value = self._post_parse_value() - return self.value + # Search for post actions in hooks + post_hook = f"post_parse__{self.name}" + if post_hook in self.hooks: + self.hooks[post_hook](self) + + return { self.name: self.value } def _prevalidate(self): if self.value in [None, ""] and not self.optional: @@ -1217,7 +1226,8 @@ ARGUMENTS_TYPE_PARSERS = { def ask_questions_and_parse_answers( - raw_questions: Dict, prefilled_answers: Union[str, Mapping[str, Any]] = {} + raw_questions: Dict, prefilled_answers: Union[str, Mapping[str, Any]] = {}, + hooks: Dict[str, Callable[[], None]] = {} ) -> List[Question]: """Parse arguments store in either manifest.json or actions.json or from a config panel against the user answers when they are present. @@ -1251,7 +1261,7 @@ def ask_questions_and_parse_answers( question_class = ARGUMENTS_TYPE_PARSERS[raw_question.get("type", "string")] raw_question["value"] = answers.get(raw_question["name"]) question = question_class(raw_question, context=answers) - answers[question.name] = question.ask_if_needed() + answers.update(question.ask_if_needed()) out.append(question) return out