Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
41b733fc41
4 changed files with 24 additions and 28 deletions
|
@ -7,25 +7,32 @@ use crate::cli::prelude::*;
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
/// Write the current config (without secrets) in TOML format
|
/// Show the current configuration in TOML format
|
||||||
Show,
|
Show(ShowArgs),
|
||||||
|
|
||||||
/// Interactively setup a Taskr configuration
|
/// Interactively setup a Taskr configuration
|
||||||
Setup,
|
Setup,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command {
|
#[derive(Args)]
|
||||||
pub async fn exec(&self, tasks: SharedTasks) -> Result<()> {
|
pub struct ShowArgs {
|
||||||
match self {
|
#[arg(short, long, default_value = None)]
|
||||||
Command::Show => self.show(tasks).await,
|
pub include_secrets: bool,
|
||||||
Command::Setup => Self::setup(tasks).await,
|
|
||||||
}
|
}
|
||||||
}
|
impl ShowArgs {
|
||||||
|
|
||||||
pub async fn show(&self, tasks: SharedTasks) -> Result<()> {
|
pub async fn show(&self, tasks: SharedTasks) -> Result<()> {
|
||||||
println!("{}", toml::to_string_pretty(tasks.config()?)?);
|
println!("{}", toml::to_string_pretty(tasks.config()?)?);
|
||||||
Ok(())
|
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<()> {
|
pub async fn setup(stasks: SharedTasks) -> Result<()> {
|
||||||
use cliclack::{intro, outro};
|
use cliclack::{intro, outro};
|
||||||
|
|
|
@ -3,35 +3,21 @@ use reqwest::{Client as RClient, Method, Url};
|
||||||
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware, RequestBuilder};
|
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware, RequestBuilder};
|
||||||
use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware};
|
use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware};
|
||||||
use reqwest_tracing::TracingMiddleware;
|
use reqwest_tracing::TracingMiddleware;
|
||||||
use serde::de;
|
use serde::{de, Serialize};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
client: ClientWithMiddleware,
|
client: ClientWithMiddleware,
|
||||||
base_url: Url,
|
base_url: Url,
|
||||||
|
|
||||||
/// If true AND compiled in debug mode, debug traces will be output for requests and responses
|
|
||||||
debug: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ResourceRequest {
|
pub trait ResourceRequest {
|
||||||
async fn is_debug(&self) -> bool;
|
|
||||||
async fn res<T: de::DeserializeOwned>(self) -> Result<T>;
|
async fn res<T: de::DeserializeOwned>(self) -> Result<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResourceRequest for RequestBuilder {
|
impl ResourceRequest for RequestBuilder {
|
||||||
async fn res<T: de::DeserializeOwned>(self) -> Result<T> {
|
async fn res<T: de::DeserializeOwned>(self) -> Result<T> {
|
||||||
use tracing::debug;
|
self.send().await?.json().await.map_err(|e| e.into())
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +60,7 @@ impl Client {
|
||||||
self.request::<T>(Method::GET, rel_url_path).await
|
self.request::<T>(Method::GET, rel_url_path).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn post<T: de::DeserializeOwned, S: se::SerializeOwnded>(
|
pub async fn post<T: de::DeserializeOwned, S: Serialize>(
|
||||||
&self,
|
&self,
|
||||||
rel_url_path: &str,
|
rel_url_path: &str,
|
||||||
body: &S,
|
body: &S,
|
||||||
|
|
|
@ -34,6 +34,8 @@ pub struct Config {
|
||||||
pub secrets: Secrets,
|
pub secrets: Secrets,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RevealedConfig {}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load(config_file_path: &Path) -> Result<Self> {
|
pub fn load(config_file_path: &Path) -> Result<Self> {
|
||||||
let mut conf = Self::build(Self::builder(config_file_path)?)?;
|
let mut conf = Self::build(Self::builder(config_file_path)?)?;
|
||||||
|
|
|
@ -3,8 +3,8 @@ use reqwest::{
|
||||||
header::{HeaderMap, HeaderValue},
|
header::{HeaderMap, HeaderValue},
|
||||||
Client as RClient,
|
Client as RClient,
|
||||||
};
|
};
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct GitLab {
|
pub struct GitLab {
|
||||||
|
@ -38,6 +38,7 @@ impl GitLab {
|
||||||
Ok(Self { client })
|
Ok(Self { client })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub async fn me(&self) -> Result<User> {
|
pub async fn me(&self) -> Result<User> {
|
||||||
self.client.get("/user").await
|
self.client.get("/user").await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue