Skip to content

Commit

Permalink
Change commands for questions
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jul 18, 2023
1 parent 55815d6 commit 2e2c108
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/agama-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
45 changes: 31 additions & 14 deletions rust/agama-cli/src/questions.rs
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,
}
}
4 changes: 2 additions & 2 deletions rust/agama-lib/src/questions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2e2c108

Please sign in to comment.