Refactor the CLI code a bit (#12782)

# Description
Refactors the code in `nu-cli`, `main.rs`, `run.rs`, and few others.
Namely, I added `EngineState::generate_nu_constant` function to
eliminate some duplicate code. Otherwise, I changed a bunch of areas to
return errors instead of calling `std::process::exit`.

# User-Facing Changes
Should be none.
This commit is contained in:
Ian Manske
2024-05-09 23:29:27 +00:00
committed by GitHub
parent 1b2e680059
commit 72d3860d05
19 changed files with 146 additions and 305 deletions

View File

@ -1,6 +1,6 @@
use nu_protocol::{
engine::{EngineState, Stack, StateWorkingSet},
report_error, Range, ShellError, Span, Value,
engine::{EngineState, Stack},
report_error_new, Range, ShellError, Span, Value,
};
use std::{ops::Bound, path::PathBuf};
@ -14,8 +14,7 @@ pub fn get_init_cwd() -> PathBuf {
pub fn get_guaranteed_cwd(engine_state: &EngineState, stack: &Stack) -> PathBuf {
engine_state.cwd(Some(stack)).unwrap_or_else(|e| {
let working_set = StateWorkingSet::new(engine_state);
report_error(&working_set, &e);
report_error_new(engine_state, &e);
crate::util::get_init_cwd()
})
}