cli: Improve node connection error
This commit is contained in:
parent
6fcdb95f0a
commit
df0b5da559
|
|
@ -0,0 +1,16 @@
|
||||||
|
When you try to track, clone, or sync without your node running, it gives you an error:
|
||||||
|
|
||||||
|
``` ~alice (fail)
|
||||||
|
$ rad track rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5 --no-fetch
|
||||||
|
✗ Track failed: to track a repository, your node must be running. To start it, run `rad node start`
|
||||||
|
```
|
||||||
|
|
||||||
|
``` ~bob (fail)
|
||||||
|
$ rad clone rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
|
||||||
|
✗ Clone failed: to clone a repository, your node must be running. To start it, run `rad node start`
|
||||||
|
```
|
||||||
|
|
||||||
|
``` ~eve (fail)
|
||||||
|
$ rad sync --fetch rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5 --seed z6MksmpU5b1dS7oaqF2bHXhQi1DWy2hB7Mh9CuN7y1DN6QSz
|
||||||
|
✗ Sync failed: to sync a repository, your node must be running. To start it, run `rad node start`
|
||||||
|
```
|
||||||
|
|
@ -106,6 +106,13 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let profile = ctx.profile()?;
|
let profile = ctx.profile()?;
|
||||||
let signer = term::signer(&profile)?;
|
let signer = term::signer(&profile)?;
|
||||||
let mut node = radicle::Node::new(profile.socket());
|
let mut node = radicle::Node::new(profile.socket());
|
||||||
|
|
||||||
|
if !node.is_running() {
|
||||||
|
anyhow::bail!(
|
||||||
|
"to clone a repository, your node must be running. To start it, run `rad node start`"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let (working, doc, proj) = clone(
|
let (working, doc, proj) = clone(
|
||||||
options.id,
|
options.id,
|
||||||
options.announce,
|
options.announce,
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,11 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut node = radicle::Node::new(profile.socket());
|
let mut node = radicle::Node::new(profile.socket());
|
||||||
|
if !node.is_running() {
|
||||||
|
anyhow::bail!(
|
||||||
|
"to sync a repository, your node must be running. To start it, run `rad node start`"
|
||||||
|
);
|
||||||
|
}
|
||||||
let mode = options.sync.mode;
|
let mode = options.sync.mode;
|
||||||
|
|
||||||
if [SyncDirection::Fetch, SyncDirection::Both].contains(&options.sync.direction) {
|
if [SyncDirection::Fetch, SyncDirection::Both].contains(&options.sync.direction) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use std::time;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
|
||||||
|
use radicle::node;
|
||||||
use radicle::node::tracking::{Alias, Scope};
|
use radicle::node::tracking::{Alias, Scope};
|
||||||
use radicle::node::{Handle, NodeId};
|
use radicle::node::{Handle, NodeId};
|
||||||
use radicle::{prelude::*, Node};
|
use radicle::{prelude::*, Node};
|
||||||
|
|
@ -118,10 +119,14 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
|
|
||||||
match options.op {
|
match options.op {
|
||||||
Operation::TrackNode { nid, alias } => {
|
Operation::TrackNode { nid, alias } => {
|
||||||
track_node(nid, alias, &mut node)?;
|
if let Err(node::Error::Connect(_)) = track_node(nid, alias, &mut node) {
|
||||||
|
anyhow::bail!("to track another node, your node must be running. To start it, run `rad node start`");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Operation::TrackRepo { rid, scope } => {
|
Operation::TrackRepo { rid, scope } => {
|
||||||
track_repo(rid, scope, &mut node)?;
|
if let Err(node::Error::Connect(_)) = track_repo(rid, scope, &mut node) {
|
||||||
|
anyhow::bail!("to track a repository, your node must be running. To start it, run `rad node start`");
|
||||||
|
}
|
||||||
|
|
||||||
if options.fetch {
|
if options.fetch {
|
||||||
sync::fetch(
|
sync::fetch(
|
||||||
|
|
@ -136,7 +141,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn track_repo(rid: Id, scope: Scope, node: &mut Node) -> anyhow::Result<()> {
|
pub fn track_repo(rid: Id, scope: Scope, node: &mut Node) -> Result<(), node::Error> {
|
||||||
let tracked = node.track_repo(rid, scope)?;
|
let tracked = node.track_repo(rid, scope)?;
|
||||||
let outcome = if tracked { "updated" } else { "exists" };
|
let outcome = if tracked { "updated" } else { "exists" };
|
||||||
|
|
||||||
|
|
@ -148,7 +153,7 @@ pub fn track_repo(rid: Id, scope: Scope, node: &mut Node) -> anyhow::Result<()>
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn track_node(nid: NodeId, alias: Option<Alias>, node: &mut Node) -> anyhow::Result<()> {
|
pub fn track_node(nid: NodeId, alias: Option<Alias>, node: &mut Node) -> Result<(), node::Error> {
|
||||||
let tracked = node.track_node(nid, alias.clone())?;
|
let tracked = node.track_node(nid, alias.clone())?;
|
||||||
let outcome = if tracked { "updated" } else { "exists" };
|
let outcome = if tracked { "updated" } else { "exists" };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -587,6 +587,37 @@ fn rad_clone_connect() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rad_sync_without_node() {
|
||||||
|
let mut environment = Environment::new();
|
||||||
|
let alice = environment.node(Config::test(Alias::new("alice")));
|
||||||
|
let bob = environment.node(Config::test(Alias::new("bob")));
|
||||||
|
let mut eve = environment.node(Config::test(Alias::new("eve")));
|
||||||
|
|
||||||
|
let rid = Id::from_urn("rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5").unwrap();
|
||||||
|
eve.tracking.track_repo(&rid, Scope::All).unwrap();
|
||||||
|
|
||||||
|
formula(&environment.tmp(), "examples/rad-sync-without-node.md")
|
||||||
|
.unwrap()
|
||||||
|
.home(
|
||||||
|
"alice",
|
||||||
|
alice.home.path(),
|
||||||
|
[("RAD_HOME", alice.home.path().display())],
|
||||||
|
)
|
||||||
|
.home(
|
||||||
|
"bob",
|
||||||
|
bob.home.path(),
|
||||||
|
[("RAD_HOME", bob.home.path().display())],
|
||||||
|
)
|
||||||
|
.home(
|
||||||
|
"eve",
|
||||||
|
eve.home.path(),
|
||||||
|
[("RAD_HOME", eve.home.path().display())],
|
||||||
|
)
|
||||||
|
.run()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rad_self() {
|
fn rad_self() {
|
||||||
let mut environment = Environment::new();
|
let mut environment = Environment::new();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue