Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error for missing install #51

Merged
merged 4 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Foreman Changelog

## Unreleased Changes
## 1.0.4 (2022-05-13)

- Introduce improved error output on using uninstalled tools ([#51](https://github.com/Roblox/foreman/pull/51))
- Add support for Apple Silicon (arm64) binaries ([#46](https://github.com/Roblox/foreman/pull/46))

## 1.0.3 (2022-02-04)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "foreman"
description = "Toolchain manager for simple binary tools"
version = "1.0.3"
version = "1.0.4"
authors = [
"Lucien Greathouse <me@lpghatguy.com>",
"Matt Hargett <plaztiksyke@gmail.com>",
Expand Down
10 changes: 10 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ impl ConfigFile {
}
}

impl fmt::Display for ConfigFile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "Available Tools:")?;
for (name, spec) in self.tools.iter() {
writeln!(f, "\t {} => {}", name, spec)?;
}
Ok(())
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
21 changes: 20 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt, io, path::PathBuf};

use semver::Version;

use crate::config::ToolSpec;
use crate::config::{ConfigFile, ToolSpec};

pub type ForemanResult<T> = Result<T, ForemanError>;

Expand Down Expand Up @@ -63,6 +63,11 @@ pub enum ForemanError {
version: Version,
message: String,
},
ToolNotInstalled {
name: String,
current_path: PathBuf,
config_file: ConfigFile,
},
}

impl ForemanError {
Expand Down Expand Up @@ -283,6 +288,20 @@ impl fmt::Display for ForemanError {
version,
message
),
Self::ToolNotInstalled {
name,
current_path,
config_file,
} => write!(
f,
"'{}' is not a known Foreman tool, but Foreman was invoked \
with its name.\n\nTo use this tool from {}, declare it in a \
'foreman.toml' file in the current directory or a parent \
directory.\n\n{}",
name,
current_path.display(),
config_file,
),
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@ impl ToolInvocation {

Ok(())
} else {
eprintln!(
"'{}' is not a known Foreman tool, but Foreman was invoked with its name.",
self.name
);
eprintln!("You may not have this tool installed here, or your install may be broken.");

Ok(())
let current_dir = env::current_dir().map_err(|err| {
ForemanError::io_error_with_context(
err,
"unable to obtain the current working directory",
)
})?;
Err(ForemanError::ToolNotInstalled {
name: self.name,
current_path: current_dir,
config_file: config,
})
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions tests/snapshots/help_command.snap
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
---
source: tests/cli.rs
assertion_line: 93
expression: content

---
foreman 1.0.3
foreman 1.0.4

USAGE:
foreman [FLAGS] <SUBCOMMAND>
Expand Down