forked from extern/nushell
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:
@ -6,6 +6,7 @@ use crate::{
|
||||
CachedFile, Command, CommandType, EnvVars, OverlayFrame, ScopeFrame, Stack, StateDelta,
|
||||
Variable, Visibility, DEFAULT_OVERLAY_NAME,
|
||||
},
|
||||
eval_const::create_nu_constant,
|
||||
BlockId, Category, Config, DeclId, Example, FileId, HistoryConfig, Module, ModuleId, OverlayId,
|
||||
ShellError, Signature, Span, Type, Value, VarId, VirtualPathId,
|
||||
};
|
||||
@ -753,8 +754,8 @@ impl EngineState {
|
||||
var.const_val.as_ref()
|
||||
}
|
||||
|
||||
pub fn set_variable_const_val(&mut self, var_id: VarId, val: Value) {
|
||||
self.vars[var_id].const_val = Some(val);
|
||||
pub fn generate_nu_constant(&mut self) {
|
||||
self.vars[NU_VARIABLE_ID].const_val = Some(create_nu_constant(self, Span::unknown()));
|
||||
}
|
||||
|
||||
pub fn get_decl(&self, decl_id: DeclId) -> &dyn Command {
|
||||
|
@ -41,7 +41,6 @@ pub fn report_error_new(
|
||||
error: &(dyn miette::Diagnostic + Send + Sync + 'static),
|
||||
) {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
|
||||
report_error(&working_set, error);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ use std::{
|
||||
};
|
||||
|
||||
/// Create a Value for `$nu`.
|
||||
pub fn create_nu_constant(engine_state: &EngineState, span: Span) -> Result<Value, ShellError> {
|
||||
pub(crate) fn create_nu_constant(engine_state: &EngineState, span: Span) -> Value {
|
||||
fn canonicalize_path(engine_state: &EngineState, path: &Path) -> PathBuf {
|
||||
#[allow(deprecated)]
|
||||
let cwd = engine_state.current_work_dir();
|
||||
@ -200,7 +200,7 @@ pub fn create_nu_constant(engine_state: &EngineState, span: Span) -> Result<Valu
|
||||
},
|
||||
);
|
||||
|
||||
Ok(Value::record(record, span))
|
||||
Value::record(record, span)
|
||||
}
|
||||
|
||||
fn eval_const_call(
|
||||
|
Reference in New Issue
Block a user