perf(dart): Lazy eval dart (#2166)
* perf(dart): evaluate version lazily * fix(dart): update format string * fix: use suggested format string Co-authored-by: Moritz Vetter <mv@3yourmind.com>
This commit is contained in:
parent
83e0432a75
commit
2532251a13
|
@ -604,12 +604,12 @@ The module will be shown if any of the following conditions are met:
|
|||
|
||||
### Options
|
||||
|
||||
| Option | Default | Description |
|
||||
| ---------- | ---------------------------------- | ----------------------------------------------- |
|
||||
| `format` | `"via [$symbol$version]($style) "` | The format for the module. |
|
||||
| `symbol` | `"🎯 "` | A format string representing the symbol of Dart |
|
||||
| `style` | `"bold blue"` | The style for the module. |
|
||||
| `disabled` | `false` | Disables the `dart` module. |
|
||||
| Option | Default | Description |
|
||||
| ---------- | ------------------------------------ | ----------------------------------------------- |
|
||||
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
|
||||
| `symbol` | `"🎯 "` | A format string representing the symbol of Dart |
|
||||
| `style` | `"bold blue"` | The style for the module. |
|
||||
| `disabled` | `false` | Disables the `dart` module. |
|
||||
|
||||
### Variables
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ pub struct DartConfig<'a> {
|
|||
impl<'a> RootModuleConfig<'a> for DartConfig<'a> {
|
||||
fn new() -> Self {
|
||||
DartConfig {
|
||||
format: "via [$symbol$version]($style) ",
|
||||
format: "via [$symbol($version )]($style)",
|
||||
symbol: "🎯 ",
|
||||
style: "bold blue",
|
||||
disabled: false,
|
||||
|
|
|
@ -22,8 +22,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||
return None;
|
||||
}
|
||||
|
||||
let dart_version = utils::exec_cmd("dart", &["--version"])?.stderr;
|
||||
|
||||
let mut module = context.new_module("dart");
|
||||
let config: DartConfig = DartConfig::try_load(module.config);
|
||||
|
||||
|
@ -38,7 +36,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||
_ => None,
|
||||
})
|
||||
.map(|variable| match variable {
|
||||
"version" => parse_dart_version(&dart_version).map(Ok),
|
||||
"version" => {
|
||||
let dart_version = utils::exec_cmd("dart", &["--version"])?.stderr;
|
||||
parse_dart_version(&dart_version).map(Ok)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.parse(None)
|
||||
|
@ -94,7 +95,7 @@ mod tests {
|
|||
File::create(dir.path().join("any.dart"))?.sync_all()?;
|
||||
|
||||
let actual = ModuleRenderer::new("dart").path(dir.path()).collect();
|
||||
let expected = Some(format!("via {} ", Color::Blue.bold().paint("🎯 v2.8.4")));
|
||||
let expected = Some(format!("via {}", Color::Blue.bold().paint("🎯 v2.8.4 ")));
|
||||
assert_eq!(expected, actual);
|
||||
dir.close()
|
||||
}
|
||||
|
@ -105,7 +106,7 @@ mod tests {
|
|||
fs::create_dir_all(dir.path().join(".dart_tool"))?;
|
||||
|
||||
let actual = ModuleRenderer::new("dart").path(dir.path()).collect();
|
||||
let expected = Some(format!("via {} ", Color::Blue.bold().paint("🎯 v2.8.4")));
|
||||
let expected = Some(format!("via {}", Color::Blue.bold().paint("🎯 v2.8.4 ")));
|
||||
assert_eq!(expected, actual);
|
||||
dir.close()
|
||||
}
|
||||
|
@ -116,7 +117,7 @@ mod tests {
|
|||
File::create(dir.path().join("pubspec.yaml"))?.sync_all()?;
|
||||
|
||||
let actual = ModuleRenderer::new("dart").path(dir.path()).collect();
|
||||
let expected = Some(format!("via {} ", Color::Blue.bold().paint("🎯 v2.8.4")));
|
||||
let expected = Some(format!("via {}", Color::Blue.bold().paint("🎯 v2.8.4 ")));
|
||||
assert_eq!(expected, actual);
|
||||
dir.close()
|
||||
}
|
||||
|
@ -127,7 +128,7 @@ mod tests {
|
|||
File::create(dir.path().join("pubspec.yml"))?.sync_all()?;
|
||||
|
||||
let actual = ModuleRenderer::new("dart").path(dir.path()).collect();
|
||||
let expected = Some(format!("via {} ", Color::Blue.bold().paint("🎯 v2.8.4")));
|
||||
let expected = Some(format!("via {}", Color::Blue.bold().paint("🎯 v2.8.4 ")));
|
||||
assert_eq!(expected, actual);
|
||||
dir.close()
|
||||
}
|
||||
|
@ -138,7 +139,7 @@ mod tests {
|
|||
File::create(dir.path().join("pubspec.lock"))?.sync_all()?;
|
||||
|
||||
let actual = ModuleRenderer::new("dart").path(dir.path()).collect();
|
||||
let expected = Some(format!("via {} ", Color::Blue.bold().paint("🎯 v2.8.4")));
|
||||
let expected = Some(format!("via {}", Color::Blue.bold().paint("🎯 v2.8.4 ")));
|
||||
assert_eq!(expected, actual);
|
||||
dir.close()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue