mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-01 01:04:00 +00:00
feat(package): support for dart pub version (#3373)
* feat(package): add support for dart pub version * feat(package): add doc for dat pub version
This commit is contained in:
parent
800fbec0cf
commit
295948bc6c
@ -2240,7 +2240,7 @@ symbol = "☁️ "
|
||||
|
||||
The `package` module is shown when the current directory is the repository for a
|
||||
package, and shows its current version. The module currently supports `npm`, `nimble`, `cargo`,
|
||||
`poetry`, `composer`, `gradle`, `julia`, `mix`, `helm` and `shards` packages.
|
||||
`poetry`, `composer`, `gradle`, `julia`, `mix`, `helm`, `shards` and `dart` packages.
|
||||
|
||||
- [**npm**](https://docs.npmjs.com/cli/commands/npm) – The `npm` package version is extracted from the `package.json` present
|
||||
in the current directory
|
||||
@ -2260,6 +2260,7 @@ package, and shows its current version. The module currently supports `npm`, `ni
|
||||
- [**Shards**](https://crystal-lang.org/reference/the_shards_command/index.html) - The `shards` package version is extracted from the `shard.yml` present
|
||||
- [**V**](https://vlang.io) - The `vlang` package version is extracted from the `v.mod` present
|
||||
- [**SBT**](https://scala-sbt.org) - The `sbt` package version is extracted from the `build.sbt` present in the current directory
|
||||
- [**Dart**](https://pub.dev/) - The `dart` package version is extracted from the `pubspec.yaml` present in the current directory
|
||||
|
||||
> ⚠️ The version being shown is that of the package whose source code is in your
|
||||
> current directory, not your package manager.
|
||||
|
@ -239,6 +239,15 @@ fn get_shard_version(context: &Context, config: &PackageConfig) -> Option<String
|
||||
format_version(raw_version, config.version_format)
|
||||
}
|
||||
|
||||
fn get_dart_pub_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
||||
let file_contents = utils::read_file(&context.current_dir.join("pubspec.yaml")).ok()?;
|
||||
|
||||
let data = yaml_rust::YamlLoader::load_from_str(&file_contents).ok()?;
|
||||
let raw_version = data.first()?["version"].as_str()?;
|
||||
|
||||
format_version(raw_version, config.version_format)
|
||||
}
|
||||
|
||||
fn get_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
||||
let package_version_fn: Vec<fn(&Context, &PackageConfig) -> Option<String>> = vec![
|
||||
get_cargo_version,
|
||||
@ -257,6 +266,7 @@ fn get_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
||||
get_vmod_version,
|
||||
get_vpkg_version,
|
||||
get_sbt_version,
|
||||
get_dart_pub_version,
|
||||
];
|
||||
|
||||
package_version_fn.iter().find_map(|f| f(context, config))
|
||||
@ -1132,6 +1142,22 @@ scalaVersion := \"2.13.7\"
|
||||
project_dir.close()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_dart_pub_version() -> io::Result<()> {
|
||||
let config_name = "pubspec.yaml";
|
||||
let config_content = "
|
||||
name: starship
|
||||
version: 1.0.0
|
||||
|
||||
environment:
|
||||
sdk: '>=2.15.0 <3.0.0'
|
||||
";
|
||||
let project_dir = create_project_dir()?;
|
||||
fill_config(&project_dir, config_name, Some(config_content))?;
|
||||
expect_output(&project_dir, Some("v1.0.0"), None);
|
||||
project_dir.close()
|
||||
}
|
||||
|
||||
fn create_project_dir() -> io::Result<TempDir> {
|
||||
tempfile::tempdir()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user