Skip to content

Commit

Permalink
feat: #18 ✨ Add support to enter a shell using the nur initialised state
Browse files Browse the repository at this point in the history
  • Loading branch information
ddanier committed May 20, 2024
1 parent 98426b2 commit bf3acfa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/engine.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use crate::args::{is_safe_taskname, parse_commandline_args, NurArgs};
use crate::errors::NurError::EnteredShellError;
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,
NUR_VAR_TASK_NAME, NUSHELL_FOLDER,
};
use crate::nu_version::NU_VERSION;
use crate::scripts::{get_default_nur_config, get_default_nur_env};
use crate::state::NurState;
use nu_cli::gather_parent_env_vars;
use nu_cli::{evaluate_repl, gather_parent_env_vars};
use nu_engine::get_full_help;
use nu_protocol::ast::Block;
use nu_protocol::engine::{Command, Stack, StateWorkingSet};
Expand Down Expand Up @@ -420,6 +421,20 @@ impl NurEngine {

let _ = std::panic::catch_unwind(move || stdout_write_all_and_flush(full_help));
}

pub(crate) fn run_repl(&mut self) -> NurResult<()> {
match evaluate_repl(
&mut self.engine_state,
self.stack.clone(),
NUSHELL_FOLDER,
None,
None,
std::time::Instant::now(),
) {
Ok(_) => Ok(()),
Err(_) => Err(EnteredShellError()),
}
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub enum NurError {
#[error("Could not find nurfile in path and parents")]
#[diagnostic()]
NurfileNotFound(),

#[error("Entered shell did raise an error")]
#[diagnostic()]
EnteredShellError(),
}

impl From<std::io::Error> for NurError {
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ fn main() -> Result<ExitCode, miette::ErrReport> {
if parsed_nur_args.debug_output {
eprintln!("full command call: {}", run_command);
}
if parsed_nur_args.quiet_execution {
if parsed_nur_args.enter_shell {
exit_code = match nur_engine.run_repl() {
Ok(_) => 0,
Err(_) => 1,
}
} else if parsed_nur_args.quiet_execution {
exit_code = nur_engine.eval_and_print(run_command, input)?;

#[cfg(feature = "debug")]
Expand Down
3 changes: 3 additions & 0 deletions src/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ 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

0 comments on commit bf3acfa

Please sign in to comment.