Skip to content

Commit

Permalink
twiq-light: Add queue remove command
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Dec 24, 2022
1 parent 5349ade commit cc2a8a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions twiq-light/src/main.rs
Expand Up @@ -8,6 +8,7 @@ mod fetch;
mod google;
mod import;
mod list_queue;
mod remove;
mod reorder;
mod search;
mod store;
Expand Down Expand Up @@ -57,6 +58,11 @@ enum QueueSubcommand {
#[arg(long, env = "TWIQ_LIGHT_GOOGLE_APPLICATION_CREDENTIALS")]
google_application_credentials: Option<String>,
},
Remove {
index: usize,
#[arg(long, env = "TWIQ_LIGHT_GOOGLE_APPLICATION_CREDENTIALS")]
google_application_credentials: Option<String>,
},
Reorder {
src: usize,
dst: usize,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions 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(())
}

0 comments on commit cc2a8a6

Please sign in to comment.