Skip to content

Commit

Permalink
fix: Fix moon bin command failing. (#626)
Browse files Browse the repository at this point in the history
* Fix bin command.

* Support shims.
  • Loading branch information
milesj authored Feb 17, 2023
1 parent ebf2e94 commit 59d1c76
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
20 changes: 12 additions & 8 deletions crates/cli/src/commands/bin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::helpers::AnyError;
use clap::ValueEnum;
use moon::load_workspace;
use moon::load_workspace_with_toolchain;
use moon_config::PlatformType;
use moon_node_tool::NodeTool;
use moon_terminal::safe_exit;
Expand All @@ -21,12 +21,16 @@ enum BinExitCodes {
}

fn is_installed(tool: &dyn Tool) {
match tool.get_bin_path() {
Ok(path) => {
println!("{}", path.display());
}
Err(_) => {
safe_exit(BinExitCodes::NotInstalled as i32);
if let Some(shim_path) = tool.get_shim_path() {
println!("{}", shim_path.display());
} else {
match tool.get_bin_path() {
Ok(path) => {
println!("{}", path.display());
}
Err(_) => {
safe_exit(BinExitCodes::NotInstalled as i32);
}
}
}
}
Expand All @@ -36,7 +40,7 @@ fn not_configured() -> ! {
}

pub async fn bin(tool_type: BinTool) -> Result<(), AnyError> {
let workspace = load_workspace().await?;
let workspace = load_workspace_with_toolchain().await?;

match tool_type {
BinTool::Node => {
Expand Down
28 changes: 18 additions & 10 deletions crates/cli/tests/bin_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ use moon_test_utils::{
create_sandbox_with_config, get_cases_fixture_configs, predicates::prelude::*,
};

// This requires installing the toolchain which is quite heavy in tests!
// #[test]
// fn valid_tool() {
// let assert = create_moon_command("cases").arg("bin").arg("node").assert();
#[test]
fn valid_tool() {
let (workspace_config, toolchain_config, tasks_config) = get_cases_fixture_configs();
let sandbox = create_sandbox_with_config(
"cases",
Some(&workspace_config),
Some(&toolchain_config),
Some(&tasks_config),
);

// assert
// .success()
// .code(0)
// .stdout("")
// .stderr(predicate::str::contains("\"unknown\" isn\'t a valid value"));
// }
let assert = sandbox.run_moon(|cmd| {
cmd.arg("bin").arg("node");
});

assert
.success()
.code(0)
.stdout(predicate::str::contains("18.0.0"));
}

#[test]
fn invalid_tool() {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Added Homebrew as an installation option.
- Added a `moon upgrade` command to upgrade moon to the latest version.

#### 🐞 Fixes

- Fixed `moon bin` failing, even when a tool has been configured.

## 0.24.1

#### 🐞 Fixes
Expand Down

0 comments on commit 59d1c76

Please sign in to comment.