trello-to-deck/src/lib.rs
Paul Campbell b3f1ed596c
Some checks failed
Test / build (map[name:nightly]) (push) Successful in 4m25s
Test / build (map[name:stable]) (push) Successful in 4m40s
Release Please / Release-plz (push) Failing after 40s
fix: stop zombie actors
Some actors had been set up so that they only stopped when all their children stopped.
The detection for this was triggered by each child as it stopped.
However, some actors didn't have any children, so were never triggered to stop.
They now check after starting any children if they should simply stop there and then.
2024-12-23 09:42:52 +00:00

138 lines
3.4 KiB
Rust

//
use std::path::PathBuf;
use clap::Parser;
use color_eyre::eyre::eyre;
use config::AppConfig;
use kxio::{fs::FileSystem, kxeprintln as e, kxprintln as p, net::Net, print::Printer};
use crate::{nextcloud::client::DeckClient, trello::client::TrelloClient};
use execute::Execute;
mod api_result;
mod check;
mod config;
mod conversion;
mod execute;
mod import;
mod init;
pub mod macros;
mod nextcloud;
mod template;
mod trello;
#[cfg(test)]
mod tests;
const NAME: &str = "trello-to-deck";
#[derive(Parser, Debug)]
#[clap(version = clap::crate_version!(), author = clap::crate_authors!(), about = clap::crate_description!())]
pub struct Commands {
#[clap(long, action = clap::ArgAction::SetTrue)]
pub log: bool,
#[clap(long, action = clap::ArgAction::SetTrue)]
pub tokio_console: bool,
#[clap(subcommand)]
pub command: Command,
}
#[derive(Parser, Debug)]
pub enum Command {
/// Initialize the configuration
#[command(about = "Initialize configuration")]
Init,
/// Check the configuration and connection
#[command(about = "Check configuration and connection")]
Check,
/// Import boards from Trello to Nextcloud Deck
#[command(about = "Import boards from Trello to Nextcloud Deck")]
Import,
/// Trello-specific commands
#[command(about = "Trello-specific commands")]
#[clap(subcommand)]
Trello(trello::TrelloCommand),
/// Nextcloud-specific commands
#[command(about = "Nextcloud-specific commands")]
#[clap(subcommand)]
Nextcloud(nextcloud::NextcloudCommand),
}
#[derive(Clone)]
pub struct Ctx {
pub fs: FileSystem,
pub net: Net,
pub prt: Printer,
}
impl From<PathBuf> for Ctx {
fn from(base: PathBuf) -> Self {
Self {
fs: kxio::fs::new(base),
net: kxio::net::new(),
prt: kxio::print::standard(),
}
}
}
#[derive(Clone)]
pub(crate) struct FullCtx {
pub fs: FileSystem,
pub net: Net,
pub prt: Printer,
pub cfg: AppConfig,
}
impl FullCtx {
pub(crate) const fn deck_client(&self) -> DeckClient {
DeckClient::new(self)
}
pub(crate) const fn trello_client(&self) -> TrelloClient {
TrelloClient::new(self)
}
}
#[cfg_attr(test, mutants::skip)]
pub async fn run(ctx: &Ctx, commands: &Commands) -> color_eyre::Result<()> {
if commands.tokio_console {
use tracing_subscriber::prelude::*;
let console_layer = console_subscriber::spawn();
tracing_subscriber::registry()
.with(console_layer)
.with(tracing_subscriber::fmt::layer())
.init();
} else if commands.log {
tracing::subscriber::set_global_default(
tracing_subscriber::FmtSubscriber::builder()
.with_max_level(tracing::Level::TRACE)
.with_env_filter("trace,hyper_util=info,kxio=info")
.finish(),
)?;
}
tracing::info!("ready");
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) => {
commands
.command
.execute(&FullCtx {
fs: ctx.fs.clone(),
net: ctx.net.clone(),
prt: ctx.prt.clone(),
cfg,
})
.await
}
}
}