mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
better error handling for nu_command::env::conig::utils::get_editor (#6430)
This commit is contained in:
parent
f1e7a01b2e
commit
f1d72e2670
3 changed files with 11 additions and 8 deletions
|
@ -58,7 +58,7 @@ impl Command for ConfigEnv {
|
|||
nu_config.push("env.nu");
|
||||
|
||||
let name = Spanned {
|
||||
item: get_editor(engine_state, stack),
|
||||
item: get_editor(engine_state, stack)?,
|
||||
span: Span { start: 0, end: 0 },
|
||||
};
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ impl Command for ConfigNu {
|
|||
nu_config.push("config.nu");
|
||||
|
||||
let name = Spanned {
|
||||
item: get_editor(engine_state, stack),
|
||||
item: get_editor(engine_state, stack)?,
|
||||
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};
|
||||
|
||||
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 env_vars = stack.get_env_vars(engine_state);
|
||||
if !config.buffer_editor.is_empty() {
|
||||
config.buffer_editor.clone()
|
||||
Ok(config.buffer_editor.clone())
|
||||
} 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") {
|
||||
value.as_string().expect("Unknown type")
|
||||
value.as_string()
|
||||
} else if cfg!(target_os = "windows") {
|
||||
"notepad".to_string()
|
||||
Ok("notepad".to_string())
|
||||
} else {
|
||||
"nano".to_string()
|
||||
Ok("nano".to_string())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue