feat(nextcloud): add command 'nextcloud stack list'
This commit is contained in:
parent
63f99c68c4
commit
f4aa3f3605
5 changed files with 81 additions and 53 deletions
13
src/lib.rs
13
src/lib.rs
|
@ -42,6 +42,8 @@ enum Command {
|
|||
enum NextcloudCommand {
|
||||
#[clap(subcommand)]
|
||||
Board(NextcloudBoardCommand),
|
||||
#[clap(subcommand)]
|
||||
Stack(NextcloudStackCommand),
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
|
@ -52,6 +54,14 @@ enum NextcloudBoardCommand {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
enum NextcloudStackCommand {
|
||||
List {
|
||||
#[clap(long, action = clap::ArgAction::SetTrue)]
|
||||
dump: bool,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Ctx {
|
||||
pub fs: FileSystem,
|
||||
|
@ -109,6 +119,9 @@ pub async fn run(ctx: Ctx) -> color_eyre::Result<()> {
|
|||
Command::Nextcloud(NextcloudCommand::Board(NextcloudBoardCommand::List {
|
||||
dump,
|
||||
})) => nextcloud::board::list(ctx, dump).await,
|
||||
Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::List {
|
||||
dump,
|
||||
})) => nextcloud::stack::list(ctx, dump).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use model::{Board, Card, NextcloudBoardId, Stack};
|
|||
|
||||
pub mod board;
|
||||
pub mod model;
|
||||
pub mod stack;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
|
|
@ -98,6 +98,7 @@ newtype!(
|
|||
newtype!(
|
||||
NextcloudStackTitle,
|
||||
String,
|
||||
Display,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
"Title of the Stack"
|
||||
|
@ -105,6 +106,7 @@ newtype!(
|
|||
newtype!(
|
||||
NextcloudCardTitle,
|
||||
String,
|
||||
Display,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
"Title of the Card"
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
//
|
||||
use crate::{p, FullCtx};
|
||||
|
||||
use super::DeckClient;
|
||||
|
||||
pub async fn list(ctx: FullCtx, dump: bool) -> color_eyre::Result<()> {
|
||||
let dc = DeckClient::new(&ctx.cfg.nextcloud, ctx.net);
|
||||
let apiresult = dc.get_stacks(ctx.cfg.nextcloud.board_id()).await;
|
||||
let api_result = ctx
|
||||
.deck_client()
|
||||
.get_stacks(ctx.cfg.nextcloud.board_id)
|
||||
.await;
|
||||
if dump {
|
||||
p!("{}", apiresult.text);
|
||||
p!(ctx.prt, "{}", api_result.text);
|
||||
} else {
|
||||
let mut stacks = apiresult.result?;
|
||||
let mut stacks = api_result.result?;
|
||||
stacks.sort_by_key(|stack| stack.order);
|
||||
stacks
|
||||
.iter()
|
||||
.for_each(|stack| p!("{}:{}", stack.id, stack.title));
|
||||
.for_each(|stack| p!(ctx.prt, "{}:{}", stack.id, stack.title));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -157,8 +157,11 @@ mod commands {
|
|||
}
|
||||
}
|
||||
|
||||
mod stack {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_stacks() {
|
||||
async fn list() {
|
||||
//given
|
||||
let mock_net = kxio::net::mock();
|
||||
|
||||
|
@ -171,7 +174,15 @@ mod commands {
|
|||
.expect("mock request");
|
||||
|
||||
let fs = given::a_filesystem();
|
||||
let ctx = given::a_full_context(mock_net, fs);
|
||||
let ctx = FullCtx {
|
||||
fs: fs.as_real(),
|
||||
net: mock_net.into(),
|
||||
prt: given::a_printer(),
|
||||
cfg: AppConfig {
|
||||
trello: given::a_trello_config(),
|
||||
nextcloud: given::a_nextcloud_config(),
|
||||
},
|
||||
};
|
||||
let deck_client = DeckClient::new(&ctx);
|
||||
|
||||
//when
|
||||
|
@ -208,6 +219,7 @@ mod commands {
|
|||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod given {
|
||||
|
|
Loading…
Reference in a new issue