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-11-30 11:30:36 +00:00
|
|
|
pub 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-11-29 14:31:40 +00:00
|
|
|
mod init;
|
2024-11-29 17:43:49 +00:00
|
|
|
mod macros;
|
2024-11-30 11:30:36 +00:00
|
|
|
pub 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-11-29 14:31:40 +00:00
|
|
|
pub const NAME: &str = "trello-to-deck";
|
|
|
|
|
2024-12-07 10:05:37 +00:00
|
|
|
pub use kxio::kxeprintln as e;
|
|
|
|
pub use kxio::kxprintln as p;
|
2024-12-08 14:39:03 +00:00
|
|
|
use nextcloud::DeckClient;
|
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!())]
|
|
|
|
struct Commands {
|
2024-12-08 10:51:19 +00:00
|
|
|
#[clap(long, action = clap::ArgAction::SetTrue)]
|
|
|
|
log: bool,
|
2024-11-29 14:31:40 +00:00
|
|
|
#[clap(subcommand)]
|
|
|
|
command: Command,
|
|
|
|
}
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
enum Command {
|
|
|
|
Init,
|
|
|
|
Check,
|
|
|
|
Import,
|
2024-12-04 19:37:39 +00:00
|
|
|
#[clap(subcommand)]
|
2024-12-05 20:07:29 +00:00
|
|
|
Trello(TrelloCommand),
|
|
|
|
#[clap(subcommand)]
|
2024-12-04 19:37:39 +00:00
|
|
|
Nextcloud(NextcloudCommand),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
enum NextcloudCommand {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
Board(NextcloudBoardCommand),
|
2024-11-30 18:04:48 +00:00
|
|
|
#[clap(subcommand)]
|
|
|
|
Stack(NextcloudStackCommand),
|
2024-11-30 18:04:48 +00:00
|
|
|
#[clap(subcommand)]
|
|
|
|
Card(NextcloudCardCommand),
|
2024-12-04 19:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
enum NextcloudBoardCommand {
|
|
|
|
List {
|
|
|
|
#[clap(long, action = clap::ArgAction::SetTrue)]
|
|
|
|
dump: bool,
|
|
|
|
},
|
2024-11-29 14:31:40 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 18:04:48 +00:00
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
enum NextcloudStackCommand {
|
|
|
|
List {
|
|
|
|
#[clap(long, action = clap::ArgAction::SetTrue)]
|
|
|
|
dump: bool,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-11-30 18:04:48 +00:00
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
enum NextcloudCardCommand {
|
|
|
|
List {
|
|
|
|
#[clap(long, action = clap::ArgAction::SetTrue)]
|
|
|
|
dump: bool,
|
|
|
|
stack_id: i64,
|
|
|
|
},
|
2024-12-07 09:56:40 +00:00
|
|
|
Get {
|
|
|
|
#[clap(long, action = clap::ArgAction::SetTrue)]
|
|
|
|
dump: bool,
|
|
|
|
stack_id: i64,
|
|
|
|
card_id: i64,
|
|
|
|
},
|
2024-12-08 14:39:03 +00:00
|
|
|
Create {
|
|
|
|
#[clap(long, action = clap::ArgAction::SetTrue)]
|
|
|
|
dump: bool,
|
|
|
|
stack_id: i64,
|
|
|
|
#[clap(long)]
|
|
|
|
title: String,
|
|
|
|
#[clap(long)]
|
|
|
|
description: Option<String>,
|
|
|
|
},
|
2024-11-30 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
2024-12-05 20:07:29 +00:00
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
enum TrelloCommand {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
Board(TrelloBoardCommand),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
enum TrelloBoardCommand {
|
|
|
|
List {
|
|
|
|
#[clap(long, action = clap::ArgAction::SetTrue)]
|
|
|
|
dump: bool,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
impl Default for Ctx {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
fs: kxio::fs::new(PathBuf::default()),
|
|
|
|
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)]
|
|
|
|
pub struct FullCtx {
|
|
|
|
pub fs: FileSystem,
|
|
|
|
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-04 20:31:36 +00:00
|
|
|
|
2024-11-29 14:31:40 +00:00
|
|
|
#[cfg_attr(test, mutants::skip)]
|
2024-11-29 14:31:40 +00:00
|
|
|
pub async fn run(ctx: Ctx) -> color_eyre::Result<()> {
|
2024-11-29 14:31:40 +00:00
|
|
|
color_eyre::install()?;
|
|
|
|
|
|
|
|
let commands = Commands::parse();
|
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-04 20:31:36 +00:00
|
|
|
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) => {
|
2024-12-04 19:37:39 +00:00
|
|
|
let ctx = FullCtx {
|
2024-12-04 20:31:36 +00:00
|
|
|
fs: ctx.fs,
|
|
|
|
net: ctx.net,
|
2024-12-07 10:05:37 +00:00
|
|
|
prt: ctx.prt,
|
2024-12-04 20:31:36 +00:00
|
|
|
cfg,
|
|
|
|
};
|
|
|
|
match commands.command {
|
|
|
|
Command::Init => Err(eyre!("Config file already exists. Not overwriting it.")),
|
2024-11-29 14:31:40 +00:00
|
|
|
Command::Check => check::run(ctx).await,
|
2024-12-04 20:31:36 +00:00
|
|
|
Command::Import => todo!("import"),
|
2024-12-08 07:24:44 +00:00
|
|
|
Command::Trello(trello) => match trello {
|
|
|
|
TrelloCommand::Board(board) => match board {
|
|
|
|
TrelloBoardCommand::List { dump } => {
|
|
|
|
nextcloud::board::list(ctx, dump).await
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Command::Nextcloud(nextcloud) => match nextcloud {
|
|
|
|
NextcloudCommand::Board(board) => match board {
|
|
|
|
NextcloudBoardCommand::List { dump } => {
|
|
|
|
nextcloud::board::list(ctx, dump).await
|
|
|
|
}
|
|
|
|
},
|
|
|
|
NextcloudCommand::Stack(stack) => match stack {
|
|
|
|
NextcloudStackCommand::List { dump } => {
|
|
|
|
nextcloud::stack::list(ctx, dump).await
|
|
|
|
}
|
|
|
|
},
|
|
|
|
NextcloudCommand::Card(card) => match card {
|
|
|
|
NextcloudCardCommand::List { dump, stack_id } => {
|
|
|
|
nextcloud::card::list(ctx, dump, stack_id.into()).await
|
|
|
|
}
|
|
|
|
NextcloudCardCommand::Get {
|
|
|
|
dump,
|
|
|
|
stack_id,
|
|
|
|
card_id,
|
|
|
|
} => nextcloud::card::get(ctx, dump, stack_id.into(), card_id.into()).await,
|
2024-12-08 14:39:03 +00:00
|
|
|
NextcloudCardCommand::Create {
|
|
|
|
dump,
|
|
|
|
stack_id,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
} => {
|
|
|
|
nextcloud::card::create(
|
|
|
|
ctx,
|
|
|
|
nextcloud::card::Create {
|
|
|
|
dump,
|
|
|
|
stack_id,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
}
|
2024-12-08 07:24:44 +00:00
|
|
|
},
|
|
|
|
},
|
2024-12-04 20:31:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-11-29 14:31:40 +00:00
|
|
|
}
|