example(fetch_and_cat): add argument: peer to connect to
@@ -24,11 +24,13 @@ async fn main() {
exit(1);
}
None => {
- eprintln!("Usage: fetch_and_cat <IPFS_PATH | CID>");
+ eprintln!("Usage: fetch_and_cat <IPFS_PATH | CID> [MULTIADDR]");
eprintln!(
"Example will accept connections and print all bytes of the unixfs file to \
stdout."
);
+ eprintln!("If second argument is present, it is expected to be a Multiaddr with \
+ peer_id. The given multiaddr will be connected to instead of waiting an incoming connection.");
exit(0);
}
};
@@ -41,11 +43,18 @@ async fn main() {
exit(1);
}
+ let target = env::args()
+ .nth(2)
+ .map(|s| s.parse::<MultiaddrWithPeerId>().unwrap());
+
// Start daemon and initialize repo
let (ipfs, fut): (Ipfs<TestTypes>, _) =
UninitializedIpfs::default().await.start().await.unwrap();
tokio::task::spawn(fut);
+ if let Some(target) = target {
+ ipfs.connect(target).await.unwrap();
+ } else {
let (_, addresses) = ipfs.identity().await.unwrap();
assert!(!addresses.is_empty(), "Zero listening addresses");
@@ -56,6 +65,7 @@ async fn main() {
}
eprintln!();
+ }
let stream = ipfs.cat_unixfs(path, None).await.unwrap_or_else(|e| {
eprintln!("Error: {}", e);
