mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Merge #8751
8751: minor: standard snippet r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
1ec82d4bdf
@ -51,16 +51,23 @@ fn rev() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn commit_hash() -> Option<String> {
|
fn commit_hash() -> Option<String> {
|
||||||
output_to_string("git rev-parse --short HEAD")
|
exec("git rev-parse --short HEAD").ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_date() -> Option<String> {
|
fn build_date() -> Option<String> {
|
||||||
output_to_string("date -u +%Y-%m-%d")
|
exec("date -u +%Y-%m-%d").ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn output_to_string(command: &str) -> Option<String> {
|
fn exec(command: &str) -> std::io::Result<String> {
|
||||||
let args = command.split_ascii_whitespace().collect::<Vec<_>>();
|
let args = command.split_ascii_whitespace().collect::<Vec<_>>();
|
||||||
let output = Command::new(args[0]).args(&args[1..]).output().ok()?;
|
let output = Command::new(args[0]).args(&args[1..]).output()?;
|
||||||
let stdout = String::from_utf8(output.stdout).ok()?;
|
if !output.status.success() {
|
||||||
Some(stdout.trim().to_string())
|
return Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::InvalidData,
|
||||||
|
format!("command {:?} returned non-zero code", command,),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let stdout = String::from_utf8(output.stdout)
|
||||||
|
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))?;
|
||||||
|
Ok(stdout.trim().to_string())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user