Prepare to write the setup stuff

This commit is contained in:
Daniel Flanagan 2024-04-18 14:15:37 -05:00
parent ab9b3647f9
commit c9be12f9c3
4 changed files with 35 additions and 7 deletions

View file

@ -3,12 +3,14 @@ use crate::cli::prelude::*;
#[derive(Subcommand)]
pub enum Command {
Show,
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,
}
}
@ -16,4 +18,10 @@ impl Command {
println!("{:#?}", tasks.config());
Ok(())
}
pub async fn setup(&self, tasks: SharedTasks) -> Result<()> {
// TODO: initialize known keyring values/entries
println!("You're all set!");
Ok(())
}
}

View file

@ -18,19 +18,41 @@ pub struct Jira {
pub url: String,
}
#[derive(Deserialize, Debug, Clone, Default)]
pub struct Secrets {
jira_token: String,
gitlab_token: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Config {
pub version: u64,
pub gitlab: Gitlab,
pub jira: Jira,
#[serde(skip_serializing)]
pub secrets: Secrets,
}
impl Config {
pub fn load(config_file_path: &Path) -> Result<Self> {
let c = Self::builder(config_file_path)?.build()?;
Ok(c.try_deserialize()
let builder = Self::builder(config_file_path)?.build()?;
let mut conf: Self = builder
.try_deserialize()
.suggestion("run `taskr config setup` to ensure valid configuration")
.with_context(|| "failed to deserialize configuration")?)
.with_context(|| "failed to deserialize configuration")?;
if conf.secrets.jira_token == "" {
conf.secrets.jira_token =
keyring::Entry::new("taskr", "gitlab_token")?.get_password()?;
}
if conf.secrets.gitlab_token == "" {
conf.secrets.gitlab_token =
keyring::Entry::new("taskr", "gitlab_token")?.get_password()?;
}
Ok(conf)
}
pub fn builder(config_file_path: &Path) -> Result<ConfigBuilder<DefaultState>>

View file

@ -12,7 +12,7 @@ mod task;
mod tasks;
mod tui;
use crate::cli::{Cli, Commands};
use crate::cli::Cli;
use crate::prelude::*;
#[tokio::main]

View file

@ -25,7 +25,6 @@ pub struct Tasks {
config: OnceLock<Config>,
gitlab: OnceLock<GitLab>,
jira: OnceLock<Jira>,
db: OnceLock<Db>,
}
@ -36,6 +35,7 @@ impl Tasks {
where
D: AsRef<Path>,
{
let db = OnceLock::new();
let config = OnceLock::new();
let gitlab = OnceLock::new();
let jira = OnceLock::new();
@ -64,8 +64,6 @@ impl Tasks {
xdg()?.create_data_directory("taskr/data")?
};
let db = OnceLock::new();
Ok(Self {
config_file_path,
config,