Moar config stuff

This commit is contained in:
Daniel Flanagan 2024-05-29 08:04:33 -05:00
parent 38912b506b
commit e1f83d54fe
4 changed files with 22 additions and 15 deletions

View file

@ -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};

View file

@ -17,15 +17,12 @@ pub trait ResourceRequest {
impl ResourceRequest for RequestBuilder {
async fn res<T: de::DeserializeOwned>(self) -> Result<T> {
// TODO: make this a field on this struct or something?
/*
use tracing::debug;
let body = self.send().await?.text().await?;
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())
}
}

View file

@ -34,6 +34,8 @@ pub struct Config {
pub secrets: Secrets,
}
pub struct RevealedConfig {}
impl Config {
pub fn load(config_file_path: &Path) -> Result<Self> {
let mut conf = Self::build(Self::builder(config_file_path)?)?;

View file

@ -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<User> {
self.client.get("/user").await
}