Skip to content

Commit

Permalink
Add tags client stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn committed Nov 18, 2024
1 parent 2bf19ac commit daad706
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use crate::{
BlobFormat, Hash, HashAndFormat, Tag,
};

pub mod tags;

/// Subcommands for the blob command.
#[allow(clippy::large_enum_variant)]
#[derive(Subcommand, Debug, Clone)]
Expand Down
46 changes: 46 additions & 0 deletions src/cli/tags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! Define the tags subcommand.

use anyhow::Result;
use bytes::Bytes;
use clap::Subcommand;
use futures_lite::StreamExt;

use crate::{rpc::client::tags, Tag};

/// Commands to manage tags.
#[derive(Subcommand, Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum TagCommands {
/// List all tags
List,
/// Delete a tag
Delete {
tag: String,
#[clap(long, default_value_t = false)]
hex: bool,
},
}

impl TagCommands {
/// Runs the tag command given the iroh client.
pub async fn run(self, tags: &tags::Client) -> Result<()> {
match self {
Self::List => {
let mut response = tags.list().await?;
while let Some(res) = response.next().await {
let res = res?;
println!("{}: {} ({:?})", res.name, res.hash, res.format);
}
}
Self::Delete { tag, hex } => {
let tag = if hex {
Tag::from(Bytes::from(hex::decode(tag)?))
} else {
Tag::from(tag)
};
tags.delete(tag).await?;
}
}
Ok(())
}
}

0 comments on commit daad706

Please sign in to comment.