From c02d6448c9450f1c119899700429a697cf37ea7f Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Wed, 16 Oct 2024 10:15:58 +0200 Subject: [PATCH] Adapted Questions subcommand to work with new --api option --- rust/agama-cli/src/lib.rs | 2 +- rust/agama-cli/src/questions.rs | 16 ++++++++-------- rust/agama-lib/src/questions/http_client.rs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rust/agama-cli/src/lib.rs b/rust/agama-cli/src/lib.rs index 10b68bfca..d43bdeb71 100644 --- a/rust/agama-cli/src/lib.rs +++ b/rust/agama-cli/src/lib.rs @@ -211,7 +211,7 @@ pub async fn run_command(cli: Cli) -> Result<(), ServiceError> { let manager = build_manager().await?; install(&manager, 3).await? } - Commands::Questions(subcommand) => run_questions_cmd(subcommand).await?, + Commands::Questions(subcommand) => run_questions_cmd(client, subcommand).await?, // TODO: logs command was originally designed with idea that agama's cli and agama // installation runs on the same machine, so it is unable to do remote connection Commands::Logs(subcommand) => run_logs_cmd(subcommand).await?, diff --git a/rust/agama-cli/src/questions.rs b/rust/agama-cli/src/questions.rs index a763f1999..1807d683b 100644 --- a/rust/agama-cli/src/questions.rs +++ b/rust/agama-cli/src/questions.rs @@ -20,7 +20,7 @@ use agama_lib::proxies::Questions1Proxy; use agama_lib::questions::http_client::HTTPClient; -use agama_lib::{connection, error::ServiceError}; +use agama_lib::{base_http_client::BaseHTTPClient, connection, error::ServiceError}; use clap::{Args, Subcommand, ValueEnum}; // TODO: use for answers also JSON to be consistent @@ -74,8 +74,8 @@ async fn set_answers(proxy: Questions1Proxy<'_>, path: String) -> Result<(), Ser .map_err(|e| e.into()) } -async fn list_questions() -> Result<(), ServiceError> { - let client = HTTPClient::new()?; +async fn list_questions(client: BaseHTTPClient) -> Result<(), ServiceError> { + let client = HTTPClient::new(client)?; let questions = client.list_questions().await?; // FIXME: if performance is bad, we can skip converting json from http to struct and then // serialize it, but it won't be pretty string @@ -85,8 +85,8 @@ async fn list_questions() -> Result<(), ServiceError> { Ok(()) } -async fn ask_question() -> Result<(), ServiceError> { - let client = HTTPClient::new()?; +async fn ask_question(client: BaseHTTPClient) -> Result<(), ServiceError> { + let client = HTTPClient::new(client)?; let question = serde_json::from_reader(std::io::stdin())?; let created_question = client.create_question(&question).await?; @@ -104,14 +104,14 @@ async fn ask_question() -> Result<(), ServiceError> { Ok(()) } -pub async fn run(subcommand: QuestionsCommands) -> Result<(), ServiceError> { +pub async fn run(client: BaseHTTPClient, subcommand: QuestionsCommands) -> Result<(), ServiceError> { let connection = connection().await?; let proxy = Questions1Proxy::new(&connection).await?; match subcommand { QuestionsCommands::Mode(value) => set_mode(proxy, value.value).await, QuestionsCommands::Answers { path } => set_answers(proxy, path).await, - QuestionsCommands::List => list_questions().await, - QuestionsCommands::Ask => ask_question().await, + QuestionsCommands::List => list_questions(client).await, + QuestionsCommands::Ask => ask_question(client).await, } } diff --git a/rust/agama-lib/src/questions/http_client.rs b/rust/agama-lib/src/questions/http_client.rs index ec0a76532..eb1ec68d4 100644 --- a/rust/agama-lib/src/questions/http_client.rs +++ b/rust/agama-lib/src/questions/http_client.rs @@ -32,9 +32,9 @@ pub struct HTTPClient { } impl HTTPClient { - pub fn new() -> Result { + pub fn new(client: BaseHTTPClient) -> Result { Ok(Self { - client: BaseHTTPClient::default().authenticated()?, + client: client, }) }