diff --git a/radicle-cli/examples/rad-inspect-noauth.md b/radicle-cli/examples/rad-inspect-noauth.md index 264ae821..21278490 100644 --- a/radicle-cli/examples/rad-inspect-noauth.md +++ b/radicle-cli/examples/rad-inspect-noauth.md @@ -2,7 +2,7 @@ The `rad inspect` command can be run without being authenticated with radicle: ``` (fail) $ rad self -✗ Error: Could not load radicle profile: no profile found at path [..] +✗ Error: Radicle profile not found in '[..]'. ✗ Hint: To setup your radicle profile, run `rad auth`. ``` diff --git a/radicle-cli/src/commands/help.rs b/radicle-cli/src/commands/help.rs index c50d1d60..dbd5342c 100644 --- a/radicle-cli/src/commands/help.rs +++ b/radicle-cli/src/commands/help.rs @@ -50,34 +50,38 @@ impl Args for Options { } pub fn run(_options: Options, ctx: impl term::Context) -> anyhow::Result<()> { - println!("Usage: rad [--help]"); + term::print("Usage: rad [--help]"); - if ctx.profile().is_err() { - println!(); - println!( - "{}", - term::format::highlight("It looks like this is your first time using radicle.") - ); - println!( - "{}", - term::format::highlight("To get started, use `rad auth` to authenticate.") - ); - println!(); + if let Err(e) = ctx.profile() { + term::blank(); + match e.downcast_ref() { + Some(term::args::Error::WithHint { err, hint }) => { + term::print(term::format::yellow(err)); + term::print(term::format::yellow(hint)); + } + Some(e) => { + term::error(e); + } + None => { + term::error(e); + } + } + term::blank(); } - println!("Common `rad` commands used in various situations:"); - println!(); + term::print("Common `rad` commands used in various situations:"); + term::blank(); for help in COMMANDS { - println!( + term::info!( "\t{} {}", term::format::bold(format!("{:-12}", help.name)), term::format::dim(help.description) ); } - println!(); - println!("See `rad --help` to learn about a specific command."); - println!(); + term::blank(); + term::print("See `rad --help` to learn about a specific command."); + term::blank(); Ok(()) } diff --git a/radicle-cli/src/terminal.rs b/radicle-cli/src/terminal.rs index f5321d94..0e5339d3 100644 --- a/radicle-cli/src/terminal.rs +++ b/radicle-cli/src/terminal.rs @@ -121,11 +121,13 @@ where pub fn profile() -> Result { match Profile::load() { Ok(profile) => Ok(profile), - Err(e) => Err(args::Error::WithHint { - err: anyhow::anyhow!("Could not load radicle profile: {e}"), + Err(radicle::profile::Error::NotFound(path)) => Err(args::Error::WithHint { + err: anyhow::anyhow!("Radicle profile not found in '{}'.", path.display()), hint: "To setup your radicle profile, run `rad auth`.", } .into()), + Err(radicle::profile::Error::Config(e)) => Err(e.into()), + Err(e) => Err(anyhow::anyhow!("Could not load radicle profile: {e}")), } } diff --git a/radicle/src/profile.rs b/radicle/src/profile.rs index 60145687..be731204 100644 --- a/radicle/src/profile.rs +++ b/radicle/src/profile.rs @@ -153,10 +153,10 @@ pub enum Error { #[derive(Debug, Error)] pub enum ConfigError { - #[error("failed to load node configuration from {0}: {1}")] + #[error("failed to load configuration from {0}: {1}")] Io(PathBuf, io::Error), - #[error("failed to decode node configuration from {0}: {1}")] - Json(PathBuf, serde_json::Error), + #[error("failed to load configuration from {0}: {1}")] + Load(PathBuf, serde_json::Error), } /// Local radicle configuration. @@ -200,7 +200,7 @@ impl Config { pub fn load(path: &Path) -> Result { match fs::File::open(path) { Ok(cfg) => { - serde_json::from_reader(cfg).map_err(|e| ConfigError::Json(path.to_path_buf(), e)) + serde_json::from_reader(cfg).map_err(|e| ConfigError::Load(path.to_path_buf(), e)) } Err(e) => { let Ok(user) = env::var("USER") else {