Skip to content

Commit 76b1473

Browse files
palozanomatheus23
andauthored
docs(iroh-cli): update blobs command documentation (#2704)
## Description Update documentation to RPC's subcommand `blobs`. This partially addresses #2660, and belongs to a series of PRs to complete it ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions Imports have been formated to be grouped. ## Change checklist - [ ] Self-review. - [X] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented. --------- Co-authored-by: Philipp Krüger <[email protected]>
1 parent 7510a59 commit 76b1473

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

iroh-cli/src/commands/blobs.rs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
use std::{
2-
collections::{BTreeMap, HashMap},
3-
net::SocketAddr,
4-
path::PathBuf,
5-
time::Duration,
6-
};
1+
//! Define blob-related commands.
72
83
use anyhow::{anyhow, bail, ensure, Context, Result};
94
use clap::Subcommand;
@@ -34,8 +29,15 @@ use iroh::{
3429
},
3530
net::{key::PublicKey, relay::RelayUrl, NodeAddr},
3631
};
32+
use std::{
33+
collections::{BTreeMap, HashMap},
34+
net::SocketAddr,
35+
path::PathBuf,
36+
time::Duration,
37+
};
3738
use tokio::io::AsyncWriteExt;
3839

40+
/// Subcommands for the blob command.
3941
#[allow(clippy::large_enum_variant)]
4042
#[derive(Subcommand, Debug, Clone)]
4143
pub enum BlobCommands {
@@ -160,6 +162,7 @@ pub enum BlobCommands {
160162
},
161163
}
162164

165+
/// Possible outcomes of an input.
163166
#[derive(Debug, Clone, derive_more::Display)]
164167
pub enum TicketOrHash {
165168
Ticket(BlobTicket),
@@ -181,6 +184,7 @@ impl std::str::FromStr for TicketOrHash {
181184
}
182185

183186
impl BlobCommands {
187+
/// Runs the blob command given the iroh client.
184188
pub async fn run(self, iroh: &Iroh) -> Result<()> {
185189
match self {
186190
Self::Get {
@@ -437,6 +441,7 @@ pub struct BlobAddOptions {
437441
pub no_ticket: bool,
438442
}
439443

444+
/// Possible list subcommands.
440445
#[derive(Subcommand, Debug, Clone)]
441446
pub enum ListCommands {
442447
/// List the available blobs on the running provider.
@@ -448,6 +453,7 @@ pub enum ListCommands {
448453
}
449454

450455
impl ListCommands {
456+
/// Runs a list subcommand.
451457
pub async fn run(self, iroh: &Iroh) -> Result<()> {
452458
match self {
453459
Self::Blobs => {
@@ -494,6 +500,7 @@ impl ListCommands {
494500
}
495501
}
496502

503+
/// Possible delete subcommands.
497504
#[derive(Subcommand, Debug, Clone)]
498505
pub enum DeleteCommands {
499506
/// Delete the given blobs
@@ -505,6 +512,7 @@ pub enum DeleteCommands {
505512
}
506513

507514
impl DeleteCommands {
515+
/// Runs the delete command.
508516
pub async fn run(self, iroh: &Iroh) -> Result<()> {
509517
match self {
510518
Self::Blob { hash } => {
@@ -518,6 +526,7 @@ impl DeleteCommands {
518526
}
519527
}
520528

529+
/// Returns the corresponding [`ReportLevel`] given the verbosity level.
521530
fn get_report_level(verbose: u8) -> ReportLevel {
522531
match verbose {
523532
0 => ReportLevel::Warn,
@@ -526,6 +535,7 @@ fn get_report_level(verbose: u8) -> ReportLevel {
526535
}
527536
}
528537

538+
/// Applies the report level to the given text.
529539
fn apply_report_level(text: String, level: ReportLevel) -> console::StyledObject<String> {
530540
match level {
531541
ReportLevel::Trace => style(text).dim(),
@@ -535,6 +545,7 @@ fn apply_report_level(text: String, level: ReportLevel) -> console::StyledObject
535545
}
536546
}
537547

548+
/// Checks the consistency of the blobs on the running node, and repairs inconsistencies if instructed.
538549
pub async fn consistency_check(iroh: &Iroh, verbose: u8, repair: bool) -> Result<()> {
539550
let mut response = iroh.blobs().consistency_check(repair).await?;
540551
let verbosity = get_report_level(verbose);
@@ -576,6 +587,7 @@ pub async fn consistency_check(iroh: &Iroh, verbose: u8, repair: bool) -> Result
576587
Ok(())
577588
}
578589

590+
/// Checks the validity of the blobs on the running node, and repairs anything invalid if instructed.
579591
pub async fn validate(iroh: &Iroh, verbose: u8, repair: bool) -> Result<()> {
580592
let mut state = ValidateProgressState::new();
581593
let mut response = iroh.blobs().validate(repair).await?;
@@ -661,6 +673,7 @@ pub async fn validate(iroh: &Iroh, verbose: u8, repair: bool) -> Result<()> {
661673
Ok(())
662674
}
663675

676+
/// Collection of all the validation progress state.
664677
struct ValidateProgressState {
665678
mp: MultiProgress,
666679
pbs: HashMap<u64, ProgressBar>,
@@ -671,6 +684,7 @@ struct ValidateProgressState {
671684
}
672685

673686
impl ValidateProgressState {
687+
/// Creates a new validation progress state collection.
674688
fn new() -> Self {
675689
let mp = MultiProgress::new();
676690
let overall = mp.add(ProgressBar::new(0));
@@ -685,6 +699,7 @@ impl ValidateProgressState {
685699
}
686700
}
687701

702+
/// Sets the total number to the provided value and style the progress bar to starting.
688703
fn starting(&mut self, total: u64) {
689704
self.total = total;
690705
self.errors = 0;
@@ -699,6 +714,7 @@ impl ValidateProgressState {
699714
);
700715
}
701716

717+
/// Adds a message to the progress bar in the given `id`.
702718
fn add_entry(&mut self, id: u64, hash: Hash, path: Option<String>, size: u64) {
703719
let pb = self.mp.insert_before(&self.overall, ProgressBar::new(size));
704720
pb.set_style(ProgressStyle::default_bar()
@@ -716,18 +732,21 @@ impl ValidateProgressState {
716732
self.pbs.insert(id, pb);
717733
}
718734

735+
/// Progresses the progress bar with `id` by `progress` amount.
719736
fn progress(&mut self, id: u64, progress: u64) {
720737
if let Some(pb) = self.pbs.get_mut(&id) {
721738
pb.set_position(progress);
722739
}
723740
}
724741

742+
/// Set an error in the progress bar. Consumes the [`ValidateProgressState`].
725743
fn abort(self, error: String) {
726744
let error_line = self.mp.add(ProgressBar::new(0));
727745
error_line.set_style(ProgressStyle::default_bar().template("{msg}").unwrap());
728746
error_line.set_message(error);
729747
}
730748

749+
/// Finishes a progress bar with a given error message.
731750
fn done(&mut self, id: u64, error: Option<String>) {
732751
if let Some(pb) = self.pbs.remove(&id) {
733752
let ok_char = style(Emoji("✔", "OK")).green();
@@ -796,6 +815,7 @@ pub enum TicketOption {
796815
Print,
797816
}
798817

818+
/// Adds a [`BlobSource`] given some [`BlobAddOptions`].
799819
pub async fn add_with_opts(
800820
client: &iroh::client::Iroh,
801821
source: BlobSource,
@@ -828,7 +848,7 @@ pub async fn add_with_opts(
828848
add(client, source, tag, ticket, wrap).await
829849
}
830850

831-
/// Add data to iroh, either from a path or, if path is `None`, from STDIN.
851+
/// Adds data to iroh, either from a path or, if path is `None`, from STDIN.
832852
pub async fn add(
833853
client: &iroh::client::Iroh,
834854
source: BlobSourceIroh,
@@ -877,13 +897,15 @@ pub async fn add(
877897
Ok(())
878898
}
879899

900+
/// Entry with a given name, size, and hash.
880901
#[derive(Debug)]
881902
pub struct ProvideResponseEntry {
882903
pub name: String,
883904
pub size: u64,
884905
pub hash: Hash,
885906
}
886907

908+
/// Combines the [`AddProgress`] outputs from a [`Stream`] into a single tuple.
887909
pub async fn aggregate_add_response(
888910
mut stream: impl Stream<Item = Result<AddProgress>> + Unpin,
889911
) -> Result<(Hash, BlobFormat, Vec<ProvideResponseEntry>)> {
@@ -947,6 +969,7 @@ pub async fn aggregate_add_response(
947969
Ok((hash, format, entries))
948970
}
949971

972+
/// Prints out the add response.
950973
pub fn print_add_response(hash: Hash, format: BlobFormat, entries: Vec<ProvideResponseEntry>) {
951974
let mut total_size = 0;
952975
for ProvideResponseEntry { name, size, hash } in entries {
@@ -961,20 +984,23 @@ pub fn print_add_response(hash: Hash, format: BlobFormat, entries: Vec<ProvideRe
961984
}
962985
}
963986

987+
/// Progress state for providing.
964988
#[derive(Debug)]
965989
pub struct ProvideProgressState {
966990
mp: MultiProgress,
967991
pbs: HashMap<u64, ProgressBar>,
968992
}
969993

970994
impl ProvideProgressState {
995+
/// Creates a new provide progress state.
971996
fn new() -> Self {
972997
Self {
973998
mp: MultiProgress::new(),
974999
pbs: HashMap::new(),
9751000
}
9761001
}
9771002

1003+
/// Inserts a new progress bar with the given id, name, and size.
9781004
fn found(&mut self, name: String, id: u64, size: u64) {
9791005
let pb = self.mp.add(ProgressBar::new(size));
9801006
pb.set_style(ProgressStyle::default_bar()
@@ -987,28 +1013,33 @@ impl ProvideProgressState {
9871013
self.pbs.insert(id, pb);
9881014
}
9891015

1016+
/// Adds some progress to the progress bar with the given id.
9901017
fn progress(&mut self, id: u64, progress: u64) {
9911018
if let Some(pb) = self.pbs.get_mut(&id) {
9921019
pb.set_position(progress);
9931020
}
9941021
}
9951022

1023+
/// Sets the multiprogress bar with the given id as finished and clear it.
9961024
fn done(&mut self, id: u64, _hash: Hash) {
9971025
if let Some(pb) = self.pbs.remove(&id) {
9981026
pb.finish_and_clear();
9991027
self.mp.remove(&pb);
10001028
}
10011029
}
10021030

1031+
/// Sets the multiprogress bar as finished and clear them.
10031032
fn all_done(self) {
10041033
self.mp.clear().ok();
10051034
}
10061035

1036+
/// Clears the multiprogress bar.
10071037
fn error(self) {
10081038
self.mp.clear().ok();
10091039
}
10101040
}
10111041

1042+
/// Displays the download progress for a given stream.
10121043
pub async fn show_download_progress(
10131044
hash: Hash,
10141045
mut stream: impl Stream<Item = Result<DownloadProgress>> + Unpin,
@@ -1124,6 +1155,7 @@ impl From<String> for OutputTarget {
11241155
}
11251156
}
11261157

1158+
/// Creates a [`ProgressBar`] with some defaults for the overall progress.
11271159
fn make_overall_progress() -> ProgressBar {
11281160
let pb = ProgressBar::hidden();
11291161
pb.enable_steady_tick(std::time::Duration::from_millis(100));
@@ -1137,6 +1169,7 @@ fn make_overall_progress() -> ProgressBar {
11371169
pb
11381170
}
11391171

1172+
/// Creates a [`ProgressBar`] with some defaults for the individual progress.
11401173
fn make_individual_progress() -> ProgressBar {
11411174
let pb = ProgressBar::hidden();
11421175
pb.enable_steady_tick(std::time::Duration::from_millis(100));

0 commit comments

Comments
 (0)