adapt dbus API to prepare for answers file and change use_defaults to…#669
adapt dbus API to prepare for answers file and change use_defaults to…#669jreidinger merged 19 commits intomasterfrom
Conversation
… interactive property
|
Changes unknown |
| log::info!("set interactive to {}", value); | ||
| if value { | ||
| if !self.interactive() { | ||
| self.answer_strategies.pop(); |
There was a problem hiding this comment.
This means that no strategies mean "no non-interactive" strategies, that is, the default strategy is interaction? Should be explicitly stated at Questions::answer_strategies declaration
There was a problem hiding this comment.
yes, no strategies means that user need to answer it itself. Will document it.
| } | ||
|
|
||
| #[test] | ||
| fn test_full_data_match() { |
There was a problem hiding this comment.
I think this test does the same thing as partial_data_match. What is the point?
There was a problem hiding this comment.
well, difference here is that first test match only one answer. But here data2 match one answer and data1 another. So it test if wins correct answer.
There was a problem hiding this comment.
I see, maybe I can express it slightly better in code or comments, will try
| <!-- | ||
| UseDefaultAnswer: | ||
| AddAnswerFile: | ||
| @path: Local fs path to answers file in yaml format. |
There was a problem hiding this comment.
NP: In Agama we are using both YaML and Json (jsonnet). It was already commented in some planning that we should converge to a single format if there is no reason to keep both. I would vote for using json everywhere: config file, autoinstall profile and questions answers.
There was a problem hiding this comment.
luckily it is easy with abstraction library provides. It is just about different crate. So when it is unify it is fine for me to convert it.
rust/agama-cli/src/questions.rs
Outdated
| proxy | ||
| .set_interactive(value == Modes::Interactive) | ||
| .await | ||
| .context("Failed to set default answer") |
There was a problem hiding this comment.
I find the error a bit misleading. What about "Failed to set the mode for answering questions".
rust/agama-cli/src/questions.rs
Outdated
| proxy | ||
| .add_answer_file(path.as_str()) | ||
| .await | ||
| .context("Failed to set default answer") |
There was a problem hiding this comment.
NP: The same here, maybe "Failed to set default answers from answers file".
|
|
||
| impl DefaultAnswers { | ||
| pub fn id() -> u8 { | ||
| 1 |
There was a problem hiding this comment.
NP: I think this can be a field of the struct.
There was a problem hiding this comment.
reason why it is also class method is to allow detection of strategy like below that instance is DefaultAnswers
| fn interactive(&self) -> bool { | ||
| let last = self.answer_strategies.last(); | ||
| if let Some(real_strategy) = last { | ||
| real_strategy.id() != DefaultAnswers::id() |
There was a problem hiding this comment.
I am not sure if I understood the idea of having more than one strategy. Is it for priorities? First from file, if no found then default, if not found then ask to user? And the mode is only considered interactive if the last assigned strategy is not DefaultAnswers. But what happens if the last strategy is answers?
There was a problem hiding this comment.
Reason for strategies is extensibility, which allows to add completely different source of answers from strategy like e.g. some remote server answering it.
So whole idea is to have list of strategies and the first one that can answer it, provide that answer.
Default strategy should be always able to answer, so it is reason why it is last as answer file has precedence. And also it means that it is non interactive.
If last strategy is answers and it does not provide answer to given question, it is asked user. It is general rule, if no strategy can answer, then ask user ( aka interactive mode ).
|
|
||
| /// Trait for objects that can provide answers to all kind of Question. | ||
| /// | ||
| /// If not strategy is used or all defined strategies does not know answer, |
There was a problem hiding this comment.
NP: a bit of rewording: "If no strategy is selected or the answer is unknown, then ask to the user".
| pub data: Option<HashMap<String, String>>, | ||
| /// The answer text is the only mandatory part of an Answer | ||
| pub answer: String, | ||
| /// All possible mixins have to be here, so they can be specified in an Answer |
There was a problem hiding this comment.
Mixins to Base Question like WithPassword. So it means that all possible additional data entries from additional mixins to question have to be specified in answer.
… interactive property
Problem
We want to have support for predefined answers and it is missing.
https://trello.com/c/9plYc08k/3373-8-agama-add-support-for-unattended-questions
Solution
Adapt dbus API to allow to add such file.
Testing
Follow-ups