diff --git a/src/cli/config.rs b/src/cli/config.rs index 76789e6..de08b61 100644 --- a/src/cli/config.rs +++ b/src/cli/config.rs @@ -7,25 +7,32 @@ use crate::cli::prelude::*; #[derive(Subcommand)] pub enum Command { - /// Write the current config (without secrets) in TOML format - Show, + /// Show the current configuration in TOML format + Show(ShowArgs), /// Interactively setup a Taskr configuration Setup, } -impl Command { - pub async fn exec(&self, tasks: SharedTasks) -> Result<()> { - match self { - Command::Show => self.show(tasks).await, - Command::Setup => Self::setup(tasks).await, - } - } - +#[derive(Args)] +pub struct ShowArgs { + #[arg(short, long, default_value = None)] + pub include_secrets: bool, +} +impl ShowArgs { pub async fn show(&self, tasks: SharedTasks) -> Result<()> { println!("{}", toml::to_string_pretty(tasks.config()?)?); Ok(()) } +} + +impl Command { + pub async fn exec(&self, tasks: SharedTasks) -> Result<()> { + match self { + Command::Show(args) => args.show(tasks).await, + Command::Setup => Self::setup(tasks).await, + } + } pub async fn setup(stasks: SharedTasks) -> Result<()> { use cliclack::{intro, outro}; diff --git a/src/client.rs b/src/client.rs index 3d6b862..68cff7b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -3,35 +3,21 @@ use reqwest::{Client as RClient, Method, Url}; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware, RequestBuilder}; use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware}; use reqwest_tracing::TracingMiddleware; -use serde::de; +use serde::{de, Serialize}; #[derive(Debug)] pub struct Client { client: ClientWithMiddleware, base_url: Url, - - /// If true AND compiled in debug mode, debug traces will be output for requests and responses - debug: bool, } pub trait ResourceRequest { - async fn is_debug(&self) -> bool; async fn res(self) -> Result; } impl ResourceRequest for RequestBuilder { async fn res(self) -> Result { - use tracing::debug; - let body = self.send().await?.text().await?; - - if self.is_debug() { - #[cfg(debug_assertions)] - debug!(body); - } - - serde_json::from_str(&body).map_err(|e| e.into()) - - // self.send().await?.json().await.map_err(|e| e.into()) + self.send().await?.json().await.map_err(|e| e.into()) } } @@ -74,7 +60,7 @@ impl Client { self.request::(Method::GET, rel_url_path).await } - pub async fn post( + pub async fn post( &self, rel_url_path: &str, body: &S, diff --git a/src/config.rs b/src/config.rs index 2d9a761..1582018 100644 --- a/src/config.rs +++ b/src/config.rs @@ -34,6 +34,8 @@ pub struct Config { pub secrets: Secrets, } +pub struct RevealedConfig {} + impl Config { pub fn load(config_file_path: &Path) -> Result { let mut conf = Self::build(Self::builder(config_file_path)?)?; diff --git a/src/gitlab.rs b/src/gitlab.rs index 4cbc395..baaad14 100644 --- a/src/gitlab.rs +++ b/src/gitlab.rs @@ -3,8 +3,8 @@ use reqwest::{ header::{HeaderMap, HeaderValue}, Client as RClient, }; - use serde::Deserialize; +use tracing::instrument; #[derive(Debug)] pub struct GitLab { @@ -38,6 +38,7 @@ impl GitLab { Ok(Self { client }) } + #[instrument] pub async fn me(&self) -> Result { self.client.get("/user").await }