1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-24 13:47:38 +00:00

fix: Check both stderr and stdout for Python version (#66)

* fix python version not showing for version < 3.4

* make review changes
This commit is contained in:
John Letey 2019-05-27 07:28:14 +01:00 committed by Matan Kushner
parent c2b0f3ac49
commit 4cd98d862d

View File

@ -46,7 +46,18 @@ pub fn segment(context: &Context) -> Option<Module> {
fn get_python_version() -> Option<String> {
match Command::new("python").arg("--version").output() {
Ok(output) => Some(String::from_utf8(output.stdout).unwrap()),
Ok(output) => {
// We have to check both stdout and stderr since for Python versions
// < 3.4, Python reports to stderr and for Python version >= 3.5,
// Python reports to stdout
if output.stdout.is_empty() {
let stderr_string = String::from_utf8(output.stderr).unwrap();
Some(stderr_string)
} else {
let stdout_string = String::from_utf8(output.stdout).unwrap();
Some(stdout_string)
}
}
Err(_) => None,
}
}