mirror of
https://github.com/starship/starship.git
synced 2025-02-08 22:39:39 +01:00
fix: check if editor is not found for configure
(#961)
* fix: check if editor is not found for `configure` STD_EDITOR falls back on `vi` if $EDITOR and $VISUAL is not set. However, some machines might not have `vi` symlinked or installed and a bad error message is displayed. This commit adds a better error message. * fix lint errors * Change NotFound to write to stderr instead of panic! Oh wow writing rust makes my commit messages look very enthusiastic!
This commit is contained in:
parent
d0e1904758
commit
7f82dd66ed
@ -1,5 +1,6 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
|
use std::io::ErrorKind;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
const STD_EDITOR: &str = "vi";
|
const STD_EDITOR: &str = "vi";
|
||||||
@ -16,11 +17,23 @@ pub fn edit_configuration() {
|
|||||||
let editor = cmd_iter.next().unwrap_or(STD_EDITOR);
|
let editor = cmd_iter.next().unwrap_or(STD_EDITOR);
|
||||||
let args: Vec<_> = cmd_iter.collect();
|
let args: Vec<_> = cmd_iter.collect();
|
||||||
|
|
||||||
Command::new(editor)
|
let command = Command::new(editor).args(args).arg(config_path).status();
|
||||||
.args(args)
|
|
||||||
.arg(config_path)
|
match command {
|
||||||
.status()
|
Ok(_) => (),
|
||||||
.expect("failed to open file");
|
Err(error) => match error.kind() {
|
||||||
|
ErrorKind::NotFound => {
|
||||||
|
eprintln!(
|
||||||
|
"Error: editor {:?} was not found. Did you set your $EDITOR or $VISUAL \
|
||||||
|
environment variables correctly?",
|
||||||
|
editor
|
||||||
|
);
|
||||||
|
eprintln!("Full error: {:?}", error);
|
||||||
|
std::process::exit(1)
|
||||||
|
}
|
||||||
|
other_error => panic!("failed to open file: {:?}", other_error),
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_editor() -> OsString {
|
fn get_editor() -> OsString {
|
||||||
|
Loading…
Reference in New Issue
Block a user