Skip to content

Commit

Permalink
fix: 🐛 Ensure code is working with nu 0.99.0 again
Browse files Browse the repository at this point in the history
  • Loading branch information
ddanier committed Oct 16, 2024
1 parent 8717fe1 commit d9d604d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ nu-utils = "0.99.0"
thiserror = "1.0.59"
miette = { version = "7.2", features = ["fancy-no-backtrace", "fancy"] }
nu-ansi-term = "0.50.1"
nu-path = "0.99.0"

[target.'cfg(not(target_os = "windows"))'.dependencies]
openssl = { version = "0.10", features = ["vendored"], optional = true }
Expand Down
7 changes: 3 additions & 4 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::errors::{NurError, NurResult};
use crate::names::{
NUR_ENV_NUR_TASK_CALL, NUR_ENV_NUR_TASK_NAME, NUR_ENV_NUR_VERSION, NUR_ENV_NU_LIB_DIRS,
NUR_NAME, NUR_VAR_CONFIG_DIR, NUR_VAR_DEFAULT_LIB_DIR, NUR_VAR_PROJECT_PATH, NUR_VAR_RUN_PATH,
NUR_VAR_TASK_NAME, NUSHELL_FOLDER,
NUR_VAR_TASK_NAME,
};
use crate::nu_version::NU_VERSION;
use crate::scripts::{get_default_nur_config, get_default_nur_env};
Expand Down Expand Up @@ -312,8 +312,8 @@ impl NurEngine {
// Merge env is requested
if merge_env {
match self.engine_state.cwd(Some(&self.stack)) {
Ok(cwd) => {
if let Err(e) = self.engine_state.merge_env(&mut self.stack, cwd) {
Ok(_cwd) => {
if let Err(e) = self.engine_state.merge_env(&mut self.stack) {
report_shell_error(&self.engine_state, &e);
}
}
Expand Down Expand Up @@ -412,7 +412,6 @@ impl NurEngine {
match evaluate_repl(
&mut self.engine_state,
self.stack.clone(),
NUSHELL_FOLDER,
None,
None,
std::time::Instant::now(),
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ use crate::compat::show_nurscripts_hint;
use crate::engine::init_engine_state;
use crate::engine::NurEngine;
use crate::errors::NurError;
use crate::path::current_dir_from_environment;
use crate::state::NurState;
use miette::Result;
use nu_ansi_term::Color;
use nu_cmd_base::util::get_init_cwd;
use nu_protocol::{ByteStream, PipelineData, Span};
use std::env;
use std::process::ExitCode;

fn main() -> Result<ExitCode, miette::ErrReport> {
// Initialise nur state
let run_path = get_init_cwd().into_std_path_buf();
let run_path = current_dir_from_environment();
let nur_state = NurState::new(run_path, env::args().collect())?;

// Create raw nu engine state
Expand Down
3 changes: 0 additions & 3 deletions src/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,3 @@ pub(crate) const NUR_VAR_DEFAULT_LIB_DIR: &str = "default-lib-dir";
// nurfile names
pub(crate) const NUR_FILE: &str = "nurfile";
pub(crate) const NUR_LOCAL_FILE: &str = "nurfile.local";

// nu shell consts
pub(crate) const NUSHELL_FOLDER: &str = "nushell"; // nu-cli -> config_files.rs, used for REPL
21 changes: 21 additions & 0 deletions src/path.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
use crate::names::NUR_FILE;
use std::path::{Path, PathBuf};

/// Get the directory where the Nushell executable is located.
fn current_exe_directory() -> PathBuf {
let mut path = std::env::current_exe().expect("current_exe() should succeed");
path.pop();
path
}

/// Get the current working directory from the environment.
pub(crate) fn current_dir_from_environment() -> PathBuf {
if let Ok(cwd) = std::env::current_dir() {
return cwd;
}
if let Ok(cwd) = std::env::var("PWD") {
return cwd.into();
}
if let Some(home) = nu_path::home_dir() {
return home.into_std_path_buf();
}
current_exe_directory()
}

pub(crate) fn find_project_path<P: AsRef<Path>>(cwd: P) -> Option<PathBuf> {
let mut path = cwd.as_ref();

Expand Down

0 comments on commit d9d604d

Please sign in to comment.