trello-to-deck/src/lib.rs
Paul Campbell 4d20ee4a9f
Some checks failed
Test / build (map[name:nightly]) (push) Successful in 1m58s
Test / build (map[name:stable]) (push) Successful in 2m55s
Release Please / Release-plz (push) Failing after 21s
feat(nextcloud): add deck_client to FullCtx
2024-12-13 09:30:16 +00:00

96 lines
2.1 KiB
Rust

//
use std::path::PathBuf;
use clap::Parser;
use color_eyre::eyre::eyre;
pub use config::AppConfig;
use kxio::{fs::FileSystem, net::Net, print::Printer};
mod api_result;
mod config;
mod init;
mod macros;
pub mod nextcloud;
mod template;
mod trello;
#[cfg(test)]
mod tests;
pub const NAME: &str = "trello-to-deck";
pub use kxio::kxeprintln as e;
pub use kxio::kxprintln as p;
use nextcloud::DeckClient;
#[derive(Parser, Debug)]
#[clap(version = clap::crate_version!(), author = clap::crate_authors!(), about = clap::crate_description!())]
struct Commands {
#[clap(subcommand)]
command: Command,
}
#[derive(Parser, Debug)]
enum Command {
Init,
Check,
Import,
}
#[derive(Clone)]
pub struct Ctx {
pub fs: FileSystem,
pub net: Net,
pub prt: Printer,
}
impl Default for Ctx {
fn default() -> Self {
Self {
fs: kxio::fs::new(PathBuf::default()),
net: kxio::net::new(),
prt: kxio::print::standard(),
}
}
}
#[derive(Clone)]
pub struct FullCtx {
pub fs: FileSystem,
pub net: Net,
pub prt: Printer,
pub cfg: AppConfig,
}
impl FullCtx {
pub fn deck_client(&self) -> DeckClient {
DeckClient::new(self)
}
}
#[cfg_attr(test, mutants::skip)]
pub async fn run(ctx: Ctx) -> color_eyre::Result<()> {
color_eyre::install()?;
let commands = Commands::parse();
let cfg = AppConfig::load(&ctx);
match cfg {
Err(err) => {
if matches!(commands.command, Command::Init) {
init::run(&ctx)
} else {
Err(eyre!("Missing or invalid config: {err}"))
}
}
Ok(cfg) => {
let _ctx = FullCtx {
fs: ctx.fs,
net: ctx.net,
prt: ctx.prt,
cfg,
};
match commands.command {
Command::Init => Err(eyre!("Config file already exists. Not overwriting it.")),
Command::Check => todo!("check"),
Command::Import => todo!("import"),
}
}
}
}