1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-11 05:42:21 +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:
Zhong Liu 2022-01-02 06:57:20 +08:00 committed by GitHub
parent 800fbec0cf
commit 295948bc6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -2240,7 +2240,7 @@ symbol = "☁️ "
The `package` module is shown when the current directory is the repository for a 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`, 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 - [**npm**](https://docs.npmjs.com/cli/commands/npm) The `npm` package version is extracted from the `package.json` present
in the current directory 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 - [**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 - [**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 - [**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 > ⚠️ The version being shown is that of the package whose source code is in your
> current directory, not your package manager. > current directory, not your package manager.

View File

@ -239,6 +239,15 @@ fn get_shard_version(context: &Context, config: &PackageConfig) -> Option<String
format_version(raw_version, config.version_format) 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> { fn get_version(context: &Context, config: &PackageConfig) -> Option<String> {
let package_version_fn: Vec<fn(&Context, &PackageConfig) -> Option<String>> = vec![ let package_version_fn: Vec<fn(&Context, &PackageConfig) -> Option<String>> = vec![
get_cargo_version, get_cargo_version,
@ -257,6 +266,7 @@ fn get_version(context: &Context, config: &PackageConfig) -> Option<String> {
get_vmod_version, get_vmod_version,
get_vpkg_version, get_vpkg_version,
get_sbt_version, get_sbt_version,
get_dart_pub_version,
]; ];
package_version_fn.iter().find_map(|f| f(context, config)) package_version_fn.iter().find_map(|f| f(context, config))
@ -1132,6 +1142,22 @@ scalaVersion := \"2.13.7\"
project_dir.close() 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> { fn create_project_dir() -> io::Result<TempDir> {
tempfile::tempdir() tempfile::tempdir()
} }