mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 07:46:28 +00:00
feat(package): Add support for crystal shards (#3147)
* add crystal shard (package) version support * module package: crystal shard version: read shard.yml directly * module package: add test for crystal shard version * format src/modules/package.rs * use yaml-rust instead of serde-yaml * document shards package support * Update docs/config/README.md Co-authored-by: David Knaack <davidkna@users.noreply.github.com> Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
This commit is contained in:
parent
c20a998d15
commit
614e0e2763
@ -2216,7 +2216,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` and `helm` packages.
|
||||
`poetry`, `composer`, `gradle`, `julia`, `mix`, `helm` and `shards` packages.
|
||||
|
||||
- [**npm**](https://docs.npmjs.com/cli/commands/npm) – The `npm` package version is extracted from the `package.json` present
|
||||
in the current directory
|
||||
@ -2233,6 +2233,7 @@ package, and shows its current version. The module currently supports `npm`, `ni
|
||||
- [**Helm**](https://helm.sh/docs/helm/helm_package/) - The `helm` chart version is extracted from the `Chart.yaml` present
|
||||
- [**Maven**](https://maven.apache.org/) - The `maven` package version is extracted from the `pom.xml` present
|
||||
- [**Meson**](https://mesonbuild.com/) - The `meson` package version is extracted from the `meson.build` 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
|
||||
|
||||
> ⚠️ The version being shown is that of the package whose source code is in your
|
||||
|
@ -223,6 +223,15 @@ fn get_nimble_version(context: &Context, config: &PackageConfig) -> Option<Strin
|
||||
format_version(raw_version, config.version_format)
|
||||
}
|
||||
|
||||
fn get_shard_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
||||
let file_contents = utils::read_file(&context.current_dir.join("shard.yml")).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,
|
||||
@ -237,6 +246,7 @@ fn get_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
||||
get_helm_package_version,
|
||||
get_maven_version,
|
||||
get_meson_version,
|
||||
get_shard_version,
|
||||
get_vmod_version,
|
||||
get_vpkg_version,
|
||||
];
|
||||
@ -546,6 +556,19 @@ license = "MIT"
|
||||
project_dir.close()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_crystal_shard_version() -> io::Result<()> {
|
||||
let config_name = "shard.yml";
|
||||
let config_content = "name: starship\nversion: 1.2.3\n".to_string();
|
||||
|
||||
let project_dir = create_project_dir()?;
|
||||
|
||||
fill_config(&project_dir, config_name, Some(&config_content))?;
|
||||
expect_output(&project_dir, Some("v1.2.3"), None);
|
||||
|
||||
project_dir.close()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_node_package_version_with_non_semantic_tag() -> io::Result<()> {
|
||||
let config_name = "package.json";
|
||||
|
Loading…
Reference in New Issue
Block a user