Skip to content

Commit 73ca073

Browse files
rklaehnmatheus23
andauthored
docs: Revive 0.35 examples (#121)
## Description Add back the examples that were removed when moving from 0.35 to 0.9x. ## Breaking Changes None ## Notes & open questions How much should we bikeshed the progress reporting in the examples, using console and indicatif crates? On the one hand it is nice, on the other hand it makes the examples more complex. I think we might put basic progress display for import, download and export into the util crate. But I think it would be nice if we could get by without the `--features exampes` feature flag for most or all examples, so maybe not use console and indicatif so we don't have to have it as dev dependencies. I changed the transfer example to use clap like the other examples. I hope you don't mind, @matheus23. ## Change checklist - [ ] Self-review. - [ ] 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. Implements #120 Implements #117 --------- Co-authored-by: Philipp Krüger <[email protected]>
1 parent 1ff13f5 commit 73ca073

File tree

7 files changed

+614
-4
lines changed

7 files changed

+614
-4
lines changed

Cargo.lock

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ testresult = "0.4.1"
5858
tracing-subscriber = { version = "0.3.19", features = ["fmt"] }
5959
tracing-test = "0.2.5"
6060
walkdir = "2.5.0"
61+
iroh = { version = "0.90", features = ["discovery-local-network"]}
6162

6263
[features]
6364
hide-proto-docs = []

examples/common/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![allow(dead_code)]
2+
use anyhow::Result;
3+
use iroh::SecretKey;
4+
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
5+
6+
/// Gets a secret key from the IROH_SECRET environment variable or generates a new random one.
7+
/// If the environment variable is set, it must be a valid string representation of a secret key.
8+
pub fn get_or_generate_secret_key() -> Result<SecretKey> {
9+
use std::{env, str::FromStr};
10+
11+
use anyhow::Context;
12+
use rand::thread_rng;
13+
if let Ok(secret) = env::var("IROH_SECRET") {
14+
// Parse the secret key from string
15+
SecretKey::from_str(&secret).context("Invalid secret key format")
16+
} else {
17+
// Generate a new random key
18+
let secret_key = SecretKey::generate(&mut thread_rng());
19+
println!(
20+
"Generated new secret key: {}",
21+
hex::encode(secret_key.to_bytes())
22+
);
23+
println!("To reuse this key, set the IROH_SECRET environment variable to this value");
24+
Ok(secret_key)
25+
}
26+
}
27+
28+
// set the RUST_LOG env var to one of {debug,info,warn} to see logging info
29+
pub fn setup_logging() {
30+
tracing_subscriber::registry()
31+
.with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr))
32+
.with(EnvFilter::from_default_env())
33+
.try_init()
34+
.ok();
35+
}

0 commit comments

Comments
 (0)