Skip to content

Commit daad706

Browse files
committed
Add tags client stuff
1 parent 2bf19ac commit daad706

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ use crate::{
3131
BlobFormat, Hash, HashAndFormat, Tag,
3232
};
3333

34+
pub mod tags;
35+
3436
/// Subcommands for the blob command.
3537
#[allow(clippy::large_enum_variant)]
3638
#[derive(Subcommand, Debug, Clone)]

src/cli/tags.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//! Define the tags subcommand.
2+
3+
use anyhow::Result;
4+
use bytes::Bytes;
5+
use clap::Subcommand;
6+
use futures_lite::StreamExt;
7+
8+
use crate::{rpc::client::tags, Tag};
9+
10+
/// Commands to manage tags.
11+
#[derive(Subcommand, Debug, Clone)]
12+
#[allow(clippy::large_enum_variant)]
13+
pub enum TagCommands {
14+
/// List all tags
15+
List,
16+
/// Delete a tag
17+
Delete {
18+
tag: String,
19+
#[clap(long, default_value_t = false)]
20+
hex: bool,
21+
},
22+
}
23+
24+
impl TagCommands {
25+
/// Runs the tag command given the iroh client.
26+
pub async fn run(self, tags: &tags::Client) -> Result<()> {
27+
match self {
28+
Self::List => {
29+
let mut response = tags.list().await?;
30+
while let Some(res) = response.next().await {
31+
let res = res?;
32+
println!("{}: {} ({:?})", res.name, res.hash, res.format);
33+
}
34+
}
35+
Self::Delete { tag, hex } => {
36+
let tag = if hex {
37+
Tag::from(Bytes::from(hex::decode(tag)?))
38+
} else {
39+
Tag::from(tag)
40+
};
41+
tags.delete(tag).await?;
42+
}
43+
}
44+
Ok(())
45+
}
46+
}

0 commit comments

Comments
 (0)