From 2e2c1081ebc9a5a849d0fde384a90a0f65418362 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 18 Jul 2023 14:03:46 +0200 Subject: [PATCH] Change commands for questions --- rust/Cargo.lock | 1 + rust/agama-cli/Cargo.toml | 1 + rust/agama-cli/src/questions.rs | 45 +++++++++++++++++++++++---------- rust/agama-lib/src/questions.rs | 4 +-- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 0b77eada04..745095d4c7 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -19,6 +19,7 @@ dependencies = [ "console", "convert_case", "indicatif", + "log", "serde", "serde_json", "serde_yaml", diff --git a/rust/agama-cli/Cargo.toml b/rust/agama-cli/Cargo.toml index 4b3078034b..38765fee9a 100644 --- a/rust/agama-cli/Cargo.toml +++ b/rust/agama-cli/Cargo.toml @@ -17,6 +17,7 @@ thiserror = "1.0.39" convert_case = "0.6.0" console = "0.15.7" anyhow = "1.0.71" +log = "0.4" [[bin]] name = "agama" diff --git a/rust/agama-cli/src/questions.rs b/rust/agama-cli/src/questions.rs index 0e3293c0c8..02535f8e0f 100644 --- a/rust/agama-cli/src/questions.rs +++ b/rust/agama-cli/src/questions.rs @@ -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, } } diff --git a/rust/agama-lib/src/questions.rs b/rust/agama-lib/src/questions.rs index 5e77f2d10b..b5e6b75970 100644 --- a/rust/agama-lib/src/questions.rs +++ b/rust/agama-lib/src/questions.rs @@ -45,9 +45,9 @@ impl GenericQuestion { /// Gets object path of given question. It is useful as parameter /// for deleting it. - /// + /// /// # Examples - /// + /// /// ``` /// use std::collections::HashMap; /// use agama_lib::questions::GenericQuestion;