2024-11-30 11:30:36 +00:00
|
|
|
//
|
2024-12-08 17:23:54 +00:00
|
|
|
use clap::Parser;
|
|
|
|
|
|
|
|
use crate::execute::Execute;
|
2024-11-30 11:30:36 +00:00
|
|
|
use crate::{p, FullCtx};
|
|
|
|
|
2024-12-08 17:23:54 +00:00
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
pub(crate) enum NextcloudStackCommand {
|
|
|
|
List {
|
|
|
|
#[clap(long, action = clap::ArgAction::SetTrue)]
|
|
|
|
dump: bool,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Execute for NextcloudStackCommand {
|
|
|
|
async fn execute(self, ctx: FullCtx) -> color_eyre::Result<()> {
|
|
|
|
match self {
|
|
|
|
Self::List { dump } => list(ctx, dump).await,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) async fn list(ctx: FullCtx, dump: bool) -> color_eyre::Result<()> {
|
2024-11-30 18:04:48 +00:00
|
|
|
let api_result = ctx
|
|
|
|
.deck_client()
|
|
|
|
.get_stacks(ctx.cfg.nextcloud.board_id)
|
|
|
|
.await;
|
2024-11-30 11:30:36 +00:00
|
|
|
if dump {
|
2024-11-30 18:04:48 +00:00
|
|
|
p!(ctx.prt, "{}", api_result.text);
|
2024-11-30 11:30:36 +00:00
|
|
|
} else {
|
2024-11-30 18:04:48 +00:00
|
|
|
let mut stacks = api_result.result?;
|
2024-11-30 11:30:36 +00:00
|
|
|
stacks.sort_by_key(|stack| stack.order);
|
|
|
|
stacks
|
|
|
|
.iter()
|
2024-11-30 18:04:48 +00:00
|
|
|
.for_each(|stack| p!(ctx.prt, "{}:{}", stack.id, stack.title));
|
2024-11-30 11:30:36 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|