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
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| ---------- | ---------------------------------- | ----------------------------------------------- |
|
| ---------- | ------------------------------------ | ----------------------------------------------- |
|
||||||
| `format` | `"via [$symbol$version]($style) "` | The format for the module. |
|
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
|
||||||
| `symbol` | `"🎯 "` | A format string representing the symbol of Dart |
|
| `symbol` | `"🎯 "` | A format string representing the symbol of Dart |
|
||||||
| `style` | `"bold blue"` | The style for the module. |
|
| `style` | `"bold blue"` | The style for the module. |
|
||||||
| `disabled` | `false` | Disables the `dart` module. |
|
| `disabled` | `false` | Disables the `dart` module. |
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub struct DartConfig<'a> {
|
||||||
impl<'a> RootModuleConfig<'a> for DartConfig<'a> {
|
impl<'a> RootModuleConfig<'a> for DartConfig<'a> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
DartConfig {
|
DartConfig {
|
||||||
format: "via [$symbol$version]($style) ",
|
format: "via [$symbol($version )]($style)",
|
||||||
symbol: "🎯 ",
|
symbol: "🎯 ",
|
||||||
style: "bold blue",
|
style: "bold blue",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
|
|
@ -22,8 +22,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dart_version = utils::exec_cmd("dart", &["--version"])?.stderr;
|
|
||||||
|
|
||||||
let mut module = context.new_module("dart");
|
let mut module = context.new_module("dart");
|
||||||
let config: DartConfig = DartConfig::try_load(module.config);
|
let config: DartConfig = DartConfig::try_load(module.config);
|
||||||
|
|
||||||
|
@ -38,7 +36,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|variable| match variable {
|
.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,
|
_ => None,
|
||||||
})
|
})
|
||||||
.parse(None)
|
.parse(None)
|
||||||
|
@ -94,7 +95,7 @@ mod tests {
|
||||||
File::create(dir.path().join("any.dart"))?.sync_all()?;
|
File::create(dir.path().join("any.dart"))?.sync_all()?;
|
||||||
|
|
||||||
let actual = ModuleRenderer::new("dart").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
|
@ -105,7 +106,7 @@ mod tests {
|
||||||
fs::create_dir_all(dir.path().join(".dart_tool"))?;
|
fs::create_dir_all(dir.path().join(".dart_tool"))?;
|
||||||
|
|
||||||
let actual = ModuleRenderer::new("dart").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
|
@ -116,7 +117,7 @@ mod tests {
|
||||||
File::create(dir.path().join("pubspec.yaml"))?.sync_all()?;
|
File::create(dir.path().join("pubspec.yaml"))?.sync_all()?;
|
||||||
|
|
||||||
let actual = ModuleRenderer::new("dart").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
|
@ -127,7 +128,7 @@ mod tests {
|
||||||
File::create(dir.path().join("pubspec.yml"))?.sync_all()?;
|
File::create(dir.path().join("pubspec.yml"))?.sync_all()?;
|
||||||
|
|
||||||
let actual = ModuleRenderer::new("dart").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
|
@ -138,7 +139,7 @@ mod tests {
|
||||||
File::create(dir.path().join("pubspec.lock"))?.sync_all()?;
|
File::create(dir.path().join("pubspec.lock"))?.sync_all()?;
|
||||||
|
|
||||||
let actual = ModuleRenderer::new("dart").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue