diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-12-06 17:08:58 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-12-06 17:08:58 +0100 |
commit | dc139e38690d30b4061ec065e2207ca6a63a662b (patch) | |
tree | 074216f082b011a5d8b499d7ccc8ece3cb9d90c3 /src | |
parent | 76bb92afc69e03e98f8d78c58e3c4c3174890fcb (diff) |
Add CLI option to connect to other node
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/cli.rs | 8 | ||||
-rw-r--r-- | src/commands/profile.rs | 13 |
2 files changed, 21 insertions, 0 deletions
@@ -41,6 +41,14 @@ pub fn app<'a>() -> App<'a> { .value_name("NAME") .about("Name of the profile") ) + + .arg(Arg::with_name("connect") + .long("connect") + .required(false) + .takes_value(true) + .value_name("MULTIADDR") + .about("Connect to MULTIADDR as well") + ) ) ) } diff --git a/src/commands/profile.rs b/src/commands/profile.rs index 93753d7..4da70f1 100644 --- a/src/commands/profile.rs +++ b/src/commands/profile.rs @@ -31,12 +31,25 @@ async fn profile_create(matches: &ArgMatches) -> Result<()> { } async fn profile_serve(matches: &ArgMatches) -> Result<()> { + use ipfs::MultiaddrWithPeerId; + let name = matches.value_of("name").map(String::from).unwrap(); // required + let connect_peer = matches.value_of("connect").map(|s| { + s.parse::<MultiaddrWithPeerId>() + .map_err(anyhow::Error::from) + }).transpose()?; + let state_dir = Profile::state_dir_path(&name)?; log::info!("Loading '{}' from {}", name, state_dir.display()); let profile = Profile::load(Config::default(), &name).await?; log::info!("Profile loaded"); + log::info!("Profile HEAD = {}", profile.head()); + + if let Some(connect_to) = connect_peer { + log::info!("Connecting to {:?}", connect_to); + profile.connect(connect_to).await?; + } let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); |