From cc2a8a62a64b5d3b767512d13d1fe8408d2ae9db Mon Sep 17 00:00:00 2001 From: bouzuya Date: Sat, 24 Dec 2022 10:58:28 +0900 Subject: [PATCH] twiq-light: Add queue remove command --- twiq-light/src/main.rs | 10 ++++++++++ twiq-light/src/remove.rs | 11 +++++++++++ 2 files changed, 21 insertions(+) create mode 100644 twiq-light/src/remove.rs diff --git a/twiq-light/src/main.rs b/twiq-light/src/main.rs index a4990fe4..ca29cf7a 100644 --- a/twiq-light/src/main.rs +++ b/twiq-light/src/main.rs @@ -8,6 +8,7 @@ mod fetch; mod google; mod import; mod list_queue; +mod remove; mod reorder; mod search; mod store; @@ -57,6 +58,11 @@ enum QueueSubcommand { #[arg(long, env = "TWIQ_LIGHT_GOOGLE_APPLICATION_CREDENTIALS")] google_application_credentials: Option, }, + Remove { + index: usize, + #[arg(long, env = "TWIQ_LIGHT_GOOGLE_APPLICATION_CREDENTIALS")] + google_application_credentials: Option, + }, Reorder { src: usize, dst: usize, @@ -118,6 +124,10 @@ async fn main() -> anyhow::Result<()> { QueueSubcommand::List { google_application_credentials, } => list_queue::run(TweetQueueStore::new(google_application_credentials)).await, + QueueSubcommand::Remove { + index, + google_application_credentials, + } => remove::run(TweetQueueStore::new(google_application_credentials), index).await, QueueSubcommand::Reorder { src, dst, diff --git a/twiq-light/src/remove.rs b/twiq-light/src/remove.rs new file mode 100644 index 00000000..87bdf95d --- /dev/null +++ b/twiq-light/src/remove.rs @@ -0,0 +1,11 @@ +use tracing::instrument; + +use crate::store::TweetQueueStore; + +#[instrument(skip_all)] +pub async fn run(store: TweetQueueStore, index: usize) -> anyhow::Result<()> { + let mut queue = store.read_all().await?; + queue.remove(index); + store.write_all(&queue).await?; + Ok(()) +}