mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-26 03:27:30 +00:00
fix(timings): count time spent on custom on 'when' command failure (#4121)
Count time spent on custom 'when' commands
This commit is contained in:
parent
e4fa652169
commit
aae1ed04ba
@ -34,6 +34,8 @@ pub fn module<'a>(name: &str, context: &'a Context) -> Option<Module<'a>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut module = Module::new(name, config.description, Some(toml_config));
|
||||||
|
|
||||||
let mut is_match = context
|
let mut is_match = context
|
||||||
.try_begin_scan()?
|
.try_begin_scan()?
|
||||||
.set_extensions(&config.detect_extensions)
|
.set_extensions(&config.detect_extensions)
|
||||||
@ -46,46 +48,42 @@ pub fn module<'a>(name: &str, context: &'a Context) -> Option<Module<'a>> {
|
|||||||
Either::First(b) => b,
|
Either::First(b) => b,
|
||||||
Either::Second(s) => exec_when(s, &config, context),
|
Either::Second(s) => exec_when(s, &config, context),
|
||||||
};
|
};
|
||||||
|
|
||||||
if !is_match {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut module = Module::new(name, config.description, Some(toml_config));
|
if is_match {
|
||||||
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
|
formatter
|
||||||
|
.map_meta(|var, _| match var {
|
||||||
|
"symbol" => Some(config.symbol),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.map_style(|variable| match variable {
|
||||||
|
"style" => Some(Ok(config.style)),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.map_no_escaping(|variable| match variable {
|
||||||
|
"output" => {
|
||||||
|
let output = exec_command(config.command, context, &config)?;
|
||||||
|
let trimmed = output.trim();
|
||||||
|
|
||||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
if trimmed.is_empty() {
|
||||||
formatter
|
None
|
||||||
.map_meta(|var, _| match var {
|
} else {
|
||||||
"symbol" => Some(config.symbol),
|
Some(Ok(trimmed.to_string()))
|
||||||
_ => None,
|
}
|
||||||
})
|
|
||||||
.map_style(|variable| match variable {
|
|
||||||
"style" => Some(Ok(config.style)),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.map_no_escaping(|variable| match variable {
|
|
||||||
"output" => {
|
|
||||||
let output = exec_command(config.command, context, &config)?;
|
|
||||||
let trimmed = output.trim();
|
|
||||||
|
|
||||||
if trimmed.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(Ok(trimmed.to_string()))
|
|
||||||
}
|
}
|
||||||
}
|
_ => None,
|
||||||
_ => None,
|
})
|
||||||
})
|
.parse(None, Some(context))
|
||||||
.parse(None, Some(context))
|
});
|
||||||
});
|
|
||||||
|
|
||||||
match parsed {
|
match parsed {
|
||||||
Ok(segments) => module.set_segments(segments),
|
Ok(segments) => module.set_segments(segments),
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
log::warn!("Error in module `custom.{}`:\n{}", name, error);
|
log::warn!("Error in module `custom.{}`:\n{}", name, error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
let elapsed = start.elapsed();
|
let elapsed = start.elapsed();
|
||||||
log::trace!("Took {:?} to compute custom module {:?}", elapsed, name);
|
log::trace!("Took {:?} to compute custom module {:?}", elapsed, name);
|
||||||
module.duration = elapsed;
|
module.duration = elapsed;
|
||||||
|
Loading…
Reference in New Issue
Block a user