2024-11-29 14:31:40 +00:00
|
|
|
//
|
|
|
|
use std::path::PathBuf;
|
2024-12-01 07:13:23 +00:00
|
|
|
|
2024-11-29 14:31:40 +00:00
|
|
|
use clap::Parser;
|
2024-12-04 20:31:36 +00:00
|
|
|
use color_eyre::eyre::eyre;
|
2024-12-08 17:23:54 +00:00
|
|
|
use config::AppConfig;
|
2024-12-07 10:05:37 +00:00
|
|
|
use kxio::{fs::FileSystem, net::Net, print::Printer};
|
2024-11-29 14:31:40 +00:00
|
|
|
|
2024-11-30 11:30:36 +00:00
|
|
|
mod api_result;
|
2024-11-29 14:31:40 +00:00
|
|
|
mod check;
|
2024-11-29 19:19:36 +00:00
|
|
|
mod config;
|
2024-12-08 17:23:54 +00:00
|
|
|
mod execute;
|
2024-12-19 09:04:23 +00:00
|
|
|
mod import;
|
2024-11-29 14:31:40 +00:00
|
|
|
mod init;
|
2024-11-29 17:43:49 +00:00
|
|
|
mod macros;
|
2024-12-08 17:23:54 +00:00
|
|
|
mod nextcloud;
|
2024-11-29 14:31:40 +00:00
|
|
|
mod template;
|
2024-12-04 20:31:36 +00:00
|
|
|
mod trello;
|
2024-11-29 14:31:40 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
2024-11-29 17:43:49 +00:00
|
|
|
|
2024-12-08 17:23:54 +00:00
|
|
|
const NAME: &str = "trello-to-deck";
|
2024-11-29 14:31:40 +00:00
|
|
|
|
2024-12-08 17:23:54 +00:00
|
|
|
use crate::nextcloud::client::DeckClient;
|
|
|
|
use crate::trello::client::TrelloClient;
|
|
|
|
use execute::Execute;
|
|
|
|
|
|
|
|
use kxio::kxeprintln as e;
|
|
|
|
use kxio::kxprintln as p;
|
2024-12-07 10:05:37 +00:00
|
|
|
|
2024-11-29 14:31:40 +00:00
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
#[clap(version = clap::crate_version!(), author = clap::crate_authors!(), about = clap::crate_description!())]
|
2024-12-15 20:07:34 +00:00
|
|
|
pub struct Commands {
|
2024-12-08 10:51:19 +00:00
|
|
|
#[clap(long, action = clap::ArgAction::SetTrue)]
|
2024-12-15 20:07:34 +00:00
|
|
|
pub log: bool,
|
2024-11-29 14:31:40 +00:00
|
|
|
#[clap(subcommand)]
|
2024-12-15 20:07:34 +00:00
|
|
|
pub command: Command,
|
2024-11-29 14:31:40 +00:00
|
|
|
}
|
|
|
|
#[derive(Parser, Debug)]
|
2024-12-15 20:07:34 +00:00
|
|
|
pub enum Command {
|
2024-12-08 17:23:54 +00:00
|
|
|
/// Initialize the configuration
|
|
|
|
#[command(about = "Initialize configuration")]
|
2024-11-29 14:31:40 +00:00
|
|
|
Init,
|
2024-12-08 17:23:54 +00:00
|
|
|
|
|
|
|
/// Check the configuration and connection
|
|
|
|
#[command(about = "Check configuration and connection")]
|
2024-11-29 14:31:40 +00:00
|
|
|
Check,
|
2024-12-08 17:23:54 +00:00
|
|
|
|
|
|
|
/// Import boards from Trello to Nextcloud Deck
|
|
|
|
#[command(about = "Import boards from Trello to Nextcloud Deck")]
|
2024-11-29 14:31:40 +00:00
|
|
|
Import,
|
2024-12-04 19:37:39 +00:00
|
|
|
|
2024-12-08 17:23:54 +00:00
|
|
|
/// Trello-specific commands
|
|
|
|
#[command(about = "Trello-specific commands")]
|
2024-12-04 19:37:39 +00:00
|
|
|
#[clap(subcommand)]
|
2024-12-08 17:23:54 +00:00
|
|
|
Trello(trello::TrelloCommand),
|
2024-12-04 19:37:39 +00:00
|
|
|
|
2024-12-08 17:23:54 +00:00
|
|
|
/// Nextcloud-specific commands
|
|
|
|
#[command(about = "Nextcloud-specific commands")]
|
2024-12-05 20:07:29 +00:00
|
|
|
#[clap(subcommand)]
|
2024-12-08 17:23:54 +00:00
|
|
|
Nextcloud(nextcloud::NextcloudCommand),
|
2024-12-05 20:07:29 +00:00
|
|
|
}
|
|
|
|
|
2024-11-29 14:31:40 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Ctx {
|
|
|
|
pub fs: FileSystem,
|
|
|
|
pub net: Net,
|
2024-12-07 10:05:37 +00:00
|
|
|
pub prt: Printer,
|
2024-11-29 14:31:40 +00:00
|
|
|
}
|
2024-12-15 17:55:23 +00:00
|
|
|
impl From<PathBuf> for Ctx {
|
|
|
|
fn from(base: PathBuf) -> Self {
|
2024-11-29 14:31:40 +00:00
|
|
|
Self {
|
2024-12-10 17:47:14 +00:00
|
|
|
fs: kxio::fs::new(base),
|
2024-11-29 14:31:40 +00:00
|
|
|
net: kxio::net::new(),
|
2024-12-07 10:05:37 +00:00
|
|
|
prt: kxio::print::standard(),
|
2024-11-29 14:31:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-11-29 14:31:40 +00:00
|
|
|
|
2024-12-04 20:31:36 +00:00
|
|
|
#[derive(Clone)]
|
2024-12-08 17:23:54 +00:00
|
|
|
pub(crate) struct FullCtx {
|
2024-12-10 17:47:14 +00:00
|
|
|
pub fs: FileSystem,
|
2024-12-04 20:31:36 +00:00
|
|
|
pub net: Net,
|
2024-12-07 10:05:37 +00:00
|
|
|
pub prt: Printer,
|
2024-12-04 20:31:36 +00:00
|
|
|
pub cfg: AppConfig,
|
|
|
|
}
|
2024-12-08 14:39:03 +00:00
|
|
|
impl FullCtx {
|
2024-12-04 19:37:39 +00:00
|
|
|
pub(crate) fn deck_client(&self) -> DeckClient {
|
2024-12-08 14:39:03 +00:00
|
|
|
DeckClient::new(self)
|
|
|
|
}
|
2024-12-08 17:23:54 +00:00
|
|
|
|
|
|
|
pub(crate) fn trello_client(&self) -> TrelloClient {
|
|
|
|
TrelloClient::new(self)
|
|
|
|
}
|
2024-12-08 14:39:03 +00:00
|
|
|
}
|
2024-12-04 20:31:36 +00:00
|
|
|
|
2024-11-29 14:31:40 +00:00
|
|
|
#[cfg_attr(test, mutants::skip)]
|
2024-12-15 20:07:34 +00:00
|
|
|
pub async fn run(ctx: &Ctx, commands: &Commands) -> color_eyre::Result<()> {
|
2024-12-08 10:51:19 +00:00
|
|
|
if commands.log {
|
|
|
|
tracing::subscriber::set_global_default(
|
|
|
|
tracing_subscriber::FmtSubscriber::builder()
|
|
|
|
.with_max_level(tracing::Level::TRACE)
|
|
|
|
.finish(),
|
|
|
|
)?;
|
|
|
|
tracing::info!("ready");
|
|
|
|
}
|
|
|
|
|
2024-12-15 20:07:34 +00:00
|
|
|
let cfg = AppConfig::load(ctx);
|
2024-12-04 20:31:36 +00:00
|
|
|
match cfg {
|
|
|
|
Err(err) => {
|
|
|
|
if matches!(commands.command, Command::Init) {
|
2024-12-15 20:07:34 +00:00
|
|
|
init::run(ctx)
|
2024-12-04 20:31:36 +00:00
|
|
|
} else {
|
|
|
|
Err(eyre!("Missing or invalid config: {err}"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(cfg) => {
|
2024-12-08 17:23:54 +00:00
|
|
|
commands
|
|
|
|
.command
|
2024-12-15 20:07:34 +00:00
|
|
|
.execute(&FullCtx {
|
|
|
|
fs: ctx.fs.clone(),
|
|
|
|
net: ctx.net.clone(),
|
|
|
|
prt: ctx.prt.clone(),
|
2024-12-08 17:23:54 +00:00
|
|
|
cfg,
|
|
|
|
})
|
|
|
|
.await
|
2024-12-04 20:31:36 +00:00
|
|
|
}
|
|
|
|
}
|
2024-11-29 14:31:40 +00:00
|
|
|
}
|