CLI automatic answers to questions#668
Conversation
imobachgs
left a comment
There was a problem hiding this comment.
I am not 100% sure about the overall approach. What happens if I want to disable this behavior? Do we need a separate command? Perhaps we use a single command like agama questions mode [interactive|defaults] or something similar.
rust/agama-cli/src/questions.rs
Outdated
|
|
||
| // TODO when more commands is added, refactor and add it to agama-lib and share a bit of functionality | ||
| async fn use_defaults() -> anyhow::Result<()> { | ||
| let connection = connection().await.context("Connection to DBus failed.")?; |
There was a problem hiding this comment.
I think there is no need to add the context because it does not add any information to the error coming from the connection function.
|
@imobachgs issue with having |
Well, as said, perhaps "interactive" is not the right word. My point is that we might want to support different strategies, and I would use a single command to set them. But I do not have a strong opinion about that. About the |
imobachgs
left a comment
There was a problem hiding this comment.
After discussing on IRC, we might need to think of a more flexible approach. But, by now, it is good enough. So let's unblock and continue from here.
rust/agama-cli/src/questions.rs
Outdated
| proxy | ||
| .use_default_answer() | ||
| .await | ||
| .context("Failed to set default answer")?; |
There was a problem hiding this comment.
| .context("Failed to set default answer")?; | |
| .context("Failed to set default answers strategy")?; |
|
Sorry, I was a bit disconnected of this topic for some time, so I had to revisit it. If I got it correctly, we could have 3 different ways for answering questions: using default answers, using answers from a file, and asking to the user. And we don't know in adavance if a command could raise a question. And then it is the problem with globally configuring the questions service, because the configuration affects to all questions, not only to the questions comming from a specific command. Well, for the global mode issue, I think it would be difficult to avoid because a new question can be dispatched after setting the mode. I would not focus on this problem now, but maybe we could explore the possibility of temporary setting the questions mode as part of the question call, and then set it back to its previous mode. And for settings the modes, I agree with a proposal similar to what @imobachgs exposed: |
| Interactive, | ||
| NonInteractive, | ||
| } | ||
| // TODO when more commands is added, refactor and add it to agama-lib and share a bit of functionality |
There was a problem hiding this comment.
Beware that the code which is specific to the CLI should live in agama-cli. That's the main intention of this package.
There was a problem hiding this comment.
well, I mean here code that handles questions, do connection, use Question API and so on. But lets see how future will look like. For rust it is nice that strict separation of public and private, so it is easy to refactor internal stuff.
Co-authored-by: Imobach González Sosa <igonzalezsosa@suse.com>
doc/cli_guidelines.md
Outdated
| ## Non Interactive Mode | ||
|
|
||
| Commands should offer a `--non-interactive` option to make scripting possible. The non interactive mode should allow answering questions automatically. | ||
| There are questions subcommand that support `mode` subcommand to set non-interactive mode. Another option is to use `answers` subcommand to pass file with |
There was a problem hiding this comment.
NP: I woud rephase it as: There is a questions subcommand that support mode and answers subcommands. The mode subcommand allows to set interactive and no-interactive modes. And answers allows to pass a file with prefefined answers.
Problem
Add to CLI ability to use default answers for questions. As we do not have yet in place questions handling, it will be for near future only way to answer it on CLI.
Solution
Add command
agama questions use-defaults. It is not as described at https://github.com/openSUSE/agama/blob/master/doc/cli_guidelines.md because currently auto answering can be only set on dbus API. Also there is risk of collision as auto answering is global for all questions, not just ones caused by given CLI command, so it can confuse user. And last but not least it can lead to some confusion where to use --non-interactive as sometimes it is hard to know what settings can cause reprobe or some action that can lead to answer.Testing
Help Output