mirror of
https://github.com/Llewellynvdm/starship.git
synced 2025-01-14 11:03:11 +00:00
feat(package): Add project version for julia (#1036)
* add project version (for julia) to package module * update docs
This commit is contained in:
parent
3ab4bab885
commit
edcec7eed8
@ -979,6 +979,7 @@ package, and shows its current version. The module currently supports `npm`, `ca
|
|||||||
- **composer** – The `composer` package version is extracted from the `composer.json` present
|
- **composer** – The `composer` package version is extracted from the `composer.json` present
|
||||||
in the current directory
|
in the current directory
|
||||||
- **gradle** – The `gradle` package version is extracted from the `build.gradle` present
|
- **gradle** – The `gradle` package version is extracted from the `build.gradle` present
|
||||||
|
- **julia** - The package version is extracted from the `Project.toml` present
|
||||||
|
|
||||||
> ⚠️ 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.
|
||||||
|
@ -86,6 +86,14 @@ fn extract_composer_version(file_contents: &str) -> Option<String> {
|
|||||||
Some(formatted_version)
|
Some(formatted_version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn extract_project_version(file_contents: &str) -> Option<String> {
|
||||||
|
let project_toml: toml::Value = toml::from_str(file_contents).ok()?;
|
||||||
|
let raw_version = project_toml.get("version")?.as_str()?;
|
||||||
|
|
||||||
|
let formatted_version = format_version(raw_version);
|
||||||
|
Some(formatted_version)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_package_version(base_dir: &PathBuf) -> Option<String> {
|
fn get_package_version(base_dir: &PathBuf) -> Option<String> {
|
||||||
if let Ok(cargo_toml) = utils::read_file(base_dir.join("Cargo.toml")) {
|
if let Ok(cargo_toml) = utils::read_file(base_dir.join("Cargo.toml")) {
|
||||||
extract_cargo_version(&cargo_toml)
|
extract_cargo_version(&cargo_toml)
|
||||||
@ -97,6 +105,8 @@ fn get_package_version(base_dir: &PathBuf) -> Option<String> {
|
|||||||
extract_composer_version(&composer_json)
|
extract_composer_version(&composer_json)
|
||||||
} else if let Ok(build_gradle) = utils::read_file(base_dir.join("build.gradle")) {
|
} else if let Ok(build_gradle) = utils::read_file(base_dir.join("build.gradle")) {
|
||||||
extract_gradle_version(&build_gradle)
|
extract_gradle_version(&build_gradle)
|
||||||
|
} else if let Ok(project_toml) = utils::read_file(base_dir.join("Project.toml")) {
|
||||||
|
extract_project_version(&project_toml)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -346,4 +356,31 @@ java {
|
|||||||
expected_version
|
expected_version
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_extract_project_version() {
|
||||||
|
let project_with_version = toml::toml! {
|
||||||
|
name = "starship"
|
||||||
|
version = "0.1.0"
|
||||||
|
}
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
let expected_version = Some("v0.1.0".to_string());
|
||||||
|
assert_eq!(
|
||||||
|
extract_project_version(&project_with_version),
|
||||||
|
expected_version
|
||||||
|
);
|
||||||
|
|
||||||
|
let project_without_version = toml::toml! {
|
||||||
|
[package]
|
||||||
|
name = "starship"
|
||||||
|
}
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
let expected_version = None;
|
||||||
|
assert_eq!(
|
||||||
|
extract_project_version(&project_without_version),
|
||||||
|
expected_version
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user