mirror of
https://github.com/nushell/nushell.git
synced 2024-11-26 02:13:47 +01:00
better error handling for nu_command::env::conig::utils::get_editor (#6430)
This commit is contained in:
parent
f1e7a01b2e
commit
f1d72e2670
@ -58,7 +58,7 @@ impl Command for ConfigEnv {
|
|||||||
nu_config.push("env.nu");
|
nu_config.push("env.nu");
|
||||||
|
|
||||||
let name = Spanned {
|
let name = Spanned {
|
||||||
item: get_editor(engine_state, stack),
|
item: get_editor(engine_state, stack)?,
|
||||||
span: Span { start: 0, end: 0 },
|
span: Span { start: 0, end: 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ impl Command for ConfigNu {
|
|||||||
nu_config.push("config.nu");
|
nu_config.push("config.nu");
|
||||||
|
|
||||||
let name = Spanned {
|
let name = Spanned {
|
||||||
item: get_editor(engine_state, stack),
|
item: get_editor(engine_state, stack)?,
|
||||||
span: Span { start: 0, end: 0 },
|
span: Span { start: 0, end: 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
15
crates/nu-command/src/env/config/utils.rs
vendored
15
crates/nu-command/src/env/config/utils.rs
vendored
@ -1,17 +1,20 @@
|
|||||||
use nu_protocol::engine::{EngineState, Stack};
|
use nu_protocol::engine::{EngineState, Stack};
|
||||||
|
|
||||||
pub(crate) fn get_editor(engine_state: &EngineState, stack: &mut Stack) -> String {
|
pub(crate) fn get_editor(
|
||||||
|
engine_state: &EngineState,
|
||||||
|
stack: &mut Stack,
|
||||||
|
) -> Result<String, nu_protocol::ShellError> {
|
||||||
let config = engine_state.get_config();
|
let config = engine_state.get_config();
|
||||||
let env_vars = stack.get_env_vars(engine_state);
|
let env_vars = stack.get_env_vars(engine_state);
|
||||||
if !config.buffer_editor.is_empty() {
|
if !config.buffer_editor.is_empty() {
|
||||||
config.buffer_editor.clone()
|
Ok(config.buffer_editor.clone())
|
||||||
} else if let Some(value) = env_vars.get("EDITOR") {
|
} else if let Some(value) = env_vars.get("EDITOR") {
|
||||||
value.as_string().expect("Unknown type")
|
value.as_string()
|
||||||
} else if let Some(value) = env_vars.get("VISUAL") {
|
} else if let Some(value) = env_vars.get("VISUAL") {
|
||||||
value.as_string().expect("Unknown type")
|
value.as_string()
|
||||||
} else if cfg!(target_os = "windows") {
|
} else if cfg!(target_os = "windows") {
|
||||||
"notepad".to_string()
|
Ok("notepad".to_string())
|
||||||
} else {
|
} else {
|
||||||
"nano".to_string()
|
Ok("nano".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user