Skip to content

Commit b14a7a8

Browse files
ramfoxb5
andauthored
docs: add full help text for lookup, connect, get, p2p, and iroh commands (#348)
* docs: add full help text for `lookup`, `connect`, `get`, `p2p`, and `iroh` commands * move long descriptions into constants Co-authored-by: b5 <sparkle_pony_2000@qri.io>
1 parent 40cb232 commit b14a7a8

File tree

4 files changed

+112
-6
lines changed

4 files changed

+112
-6
lines changed

iroh/src/doc.rs

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
pub const IROH_LONG_DESCRIPTION: &str = "
2+
Iroh is a next-generation implementation the Interplanetary File System (IPFS).
3+
IPFS is a networking protocol for exchanging content-addressed blocks of
4+
immutable data. 'content-addressed' means referring to data by the hash of it's
5+
content, which makes the reference both unique and verifiable. These two
6+
properties make it possible to get data from any node in the network that speaks
7+
the IPFS protocol, including IPFS content being served by other implementations
8+
of the protocol.
9+
10+
For more info see https://iroh.computer/docs";
11+
12+
pub const STATUS_LONG_DESCRIPTION: &str = "
13+
status reports the current operational setup of iroh. Use status as a go-to
14+
command for understanding where iroh commands are being processed. different
15+
ops configurations utilize different network and service implementations
16+
under the hood, which can lead to varying performance characteristics.
17+
18+
Status reports connectivity, which is either offline or online:
19+
20+
offline: iroh is not connected to any background process, all commands
21+
are one-off, any network connections are closed when a command
22+
completes. Some network duties may be delegated to remote hosts.
23+
24+
online: iroh has found a long-running process to issue commands to. Any
25+
comand issued will be deletegated to the long-running process as a
26+
remote procedure call
27+
28+
If iroh is online, status also reports the service configuration of the
29+
long running process, including the health of the configured subsystem(s).
30+
Possible configurations fall into two buckets:
31+
32+
one: Iroh is running with all services bundled into one single process,
33+
this setup is common in desktop enviornments.
34+
35+
cloud: Iroh is running with services split into separate processes, which
36+
are speaking to each other via remote procedure calls.
37+
38+
Use the --watch flag to continually poll for changes.
39+
40+
Status reports no metrics about the running system aside from current service
41+
health. Instead all metrics are emitted through uniform tracing collection &
42+
reporting, which is intended to be consumed by tools like prometheus and
43+
grafana. For more info on metrics collection, see
44+
https://iroh.computer/docs/metrics";
45+
46+
pub const GET_LONG_DESCRIPTION: &str = "
47+
Download file or directory specified by <ipfs-path> from IPFS into [path]. If
48+
path already exists and is a file then it's overwritten with the new downloaded
49+
file. If path already exists and is a directory, the command fails with an
50+
error. If path already exists, is a file and the downloaded data is a directory,
51+
that's an error.
52+
53+
By default, the output will be written to the working directory. If no file or
54+
directory name can be derived from the <ipfs-path>, the output will be written
55+
to the given path's CID.
56+
57+
If <ipfs-path> is already present in the iroh store, no network call will
58+
be made.";
59+
60+
pub const P2P_CONNECT_LONG_DESCRIPTION: &str = "
61+
Attempts to open a new direct connection to a peer address. By default p2p
62+
continulously maintains an open set of peer connections based on requests &
63+
internal hueristics. Connect is useful in situations where it makes sense to
64+
manually force libp2p to dial a known peer. A common example includes when you
65+
know the multiaddr or peer ID of a peer that you would like to exchange data
66+
with.
67+
68+
The address format is in multiaddr format. For example:
69+
70+
> iroh p2p connect /ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
71+
72+
for more info on multiaddrs see https://iroh.computer/docs/concepts#multiaddr
73+
74+
If a peer ID is provided, connect first perform a distribtued hash table (DHT)
75+
lookup to learn the address of the given peer ID before dialing.";
76+
77+
pub const P2P_LOOKUP_LONG_DESCRIPTION: &str = "
78+
Takes as input a peer ID or address and prints the output of the libp2p-identify
79+
protocol. When provided with a peer ID, the address is looked up on the
80+
Network's Distributed Hash Table (DHT) before connecting to the node. When
81+
provided with a multiaddress, the connection is dialed directly.
82+
83+
Providing no <ADDR> argument will return your local node information.";

iroh/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod doc;
12
#[cfg(feature = "testing")]
23
mod fixture;
34
pub mod metrics;

iroh/src/p2p.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1-
use std::str::FromStr;
2-
1+
use crate::doc;
32
use anyhow::{Error, Result};
43
use clap::{Args, Subcommand};
54
use iroh_api::{Multiaddr, P2pApi, PeerId, PeerIdOrAddr};
5+
use std::str::FromStr;
66

77
#[derive(Args, Debug, Clone)]
8-
#[clap(about = "Manage peer-2-peer networking.")]
8+
#[clap(about = "Peer-2-peer commands")]
9+
#[clap(
10+
after_help = "p2p commands all relate to peer-2-peer connectivity. See subcommands for
11+
additional details."
12+
)]
913
pub struct P2p {
1014
#[clap(subcommand)]
1115
command: P2pCommands,
1216
}
1317

1418
#[derive(Subcommand, Debug, Clone)]
1519
pub enum P2pCommands {
20+
#[clap(about = "Connect to a peer")]
21+
#[clap(after_help = doc::P2P_CONNECT_LONG_DESCRIPTION)]
22+
Connect {
23+
/// Multiaddr or peer ID of a peer to connect to
24+
addr: PeerIdOrAddrArg,
25+
},
1626
#[clap(about = "Retrieve info about a node")]
17-
Lookup { addr: PeerIdOrAddrArg },
27+
#[clap(after_help = doc::P2P_LOOKUP_LONG_DESCRIPTION)]
28+
Lookup {
29+
/// multiaddress or peer ID
30+
addr: PeerIdOrAddrArg,
31+
},
1832
}
1933

2034
#[derive(Debug, Clone)]
@@ -35,6 +49,9 @@ impl FromStr for PeerIdOrAddrArg {
3549

3650
pub async fn run_command(p2p: &impl P2pApi, cmd: &P2p) -> Result<()> {
3751
match &cmd.command {
52+
P2pCommands::Connect { .. } => {
53+
todo!("`iroh p2p connect` is not yet implemented")
54+
}
3855
P2pCommands::Lookup { addr } => {
3956
let lookup = p2p.lookup(&addr.0).await?;
4057
println!("peer id: {}", lookup.peer_id);

iroh/src/run.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::HashMap;
22
use std::path::PathBuf;
33

4+
use crate::doc;
45
#[cfg(feature = "testing")]
56
use crate::fixture::get_fixture_api;
67
use crate::p2p::{run_command as run_p2p_command, P2p};
@@ -10,7 +11,9 @@ use iroh_api::{Api, ApiExt, IpfsPath, Iroh};
1011
use iroh_metrics::config::Config as MetricsConfig;
1112

1213
#[derive(Parser, Debug, Clone)]
13-
#[clap(version, about, long_about = None, propagate_version = true)]
14+
#[clap(version, long_about = None, propagate_version = true)]
15+
#[clap(about = "A next generation IPFS implementation: https://iroh.computer")]
16+
#[clap(after_help = doc::IROH_LONG_DESCRIPTION)]
1417
pub struct Cli {
1518
#[clap(long)]
1619
cfg: Option<PathBuf>,
@@ -33,9 +36,10 @@ impl Cli {
3336
enum Commands {
3437
// status checks the health of the different processes
3538
#[clap(about = "Check the health of the different iroh processes.")]
39+
#[clap(after_help = doc::STATUS_LONG_DESCRIPTION)]
3640
Status {
3741
#[clap(short, long)]
38-
/// when true, updates the status table whenever a change in a process's status occurs
42+
/// Poll process for changes
3943
watch: bool,
4044
},
4145
P2p(P2p),
@@ -51,6 +55,7 @@ enum Commands {
5155
no_wrap: bool,
5256
},
5357
#[clap(about = "Fetch IPFS content and write it to disk")]
58+
#[clap(after_help = doc::GET_LONG_DESCRIPTION )]
5459
Get {
5560
/// CID or CID/with/path/qualifier to get
5661
ipfs_path: IpfsPath,

0 commit comments

Comments
 (0)