-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} | ||
} |