-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55815d6
commit 2e2c108
Showing
4 changed files
with
35 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,49 @@ | ||
use agama_lib::connection; | ||
use agama_lib::proxies::Questions1Proxy; | ||
use anyhow::{Context, Ok}; | ||
use clap::Subcommand; | ||
use clap::{Args, Subcommand, ValueEnum}; | ||
use log; | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub enum QuestionsCommands { | ||
/// To use default answers for questions. | ||
UseDefaults, | ||
/// Set mode for answering questions. | ||
Mode(ModesArgs), | ||
} | ||
|
||
#[derive(Args, Debug)] | ||
pub struct ModesArgs { | ||
#[arg(value_enum)] | ||
value: Modes, | ||
} | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] | ||
pub enum Modes { | ||
Interactive, | ||
NonInteractive, | ||
} | ||
// 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.")?; | ||
let proxy = Questions1Proxy::new(&connection) | ||
.await | ||
.context("Failed to connect to Questions service")?; | ||
async fn set_mode(value: Modes) -> anyhow::Result<()> { | ||
match value { | ||
Modes::NonInteractive => { | ||
let connection = connection().await?; | ||
let proxy = Questions1Proxy::new(&connection) | ||
.await | ||
.context("Failed to connect to Questions service")?; | ||
|
||
// TODO: how to print dbus error in that anyhow? | ||
proxy | ||
.use_default_answer() | ||
.await | ||
.context("Failed to set default answer")?; | ||
// TODO: how to print dbus error in that anyhow? | ||
proxy | ||
.use_default_answer() | ||
.await | ||
.context("Failed to set default answer")?; | ||
} | ||
Modes::Interactive => log::info!("not implemented"), //TODO do it | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub async fn run(subcommand: QuestionsCommands) -> anyhow::Result<()> { | ||
match subcommand { | ||
QuestionsCommands::UseDefaults => use_defaults().await, | ||
QuestionsCommands::Mode(value) => set_mode(value.value).await, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters