mirror of
https://github.com/starship/starship.git
synced 2026-06-24 02:01:36 +07:00
feat: Add version formating for modules (#2611)
* format crystal version with VersionFormatter * update crystal dosc * format crystal module * fix typos * format dart version with VersionFormatter * fix dart malformed test * update dart docs * format cmake version with VersionFormatter * update cmake docs * format deno version with VersionFormatter * update deno docs * remove Version type * format dotnet version with VersionFormatter * update dotnet docs * format erlang version with VersionFormatter * update erlang docs * format golang version with VersionFormatter * refactor formatting in my modules * format helm version with VersionFormatter * format julia version with VersionFormatter * format kotlin version with VersionFormatter * format lua version with VersionFormatter * format nim version with VersionFormatter * format perl version with VersionFormatter * format php version with VersionFormatter * format purescript version with VersionFormatter * format scala version with VersionFormatter * format swift version with VersionFormatter * format terraform version with VersionFormatter * format vagrant version with VersionFormatter * format zig version with VersionFormatter * format elixir version with VersionFormatter * format ocaml version with VersionFormatter * update elixir docs * update golang docs * update helm docs * update julia docs * update kotlin docs * update lua docs * update nim docs * update ocaml docs * update perl docs * update php docs * update purescript docs * update scala docs * update swift docs * update terraform docs * update vagrant docs * update zig docs * format elm version with VersionFormatter * update elm docs * pass module_name as &str to format_module_version
This commit is contained in:
+19
-14
@@ -2,6 +2,7 @@ use super::{Context, Module, RootModuleConfig};
|
||||
|
||||
use crate::configs::crystal::CrystalConfig;
|
||||
use crate::formatter::StringFormatter;
|
||||
use crate::formatter::VersionFormatter;
|
||||
|
||||
/// Creates a module with the current Crystal version
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
@@ -30,9 +31,15 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
_ => None,
|
||||
})
|
||||
.map(|variable| match variable {
|
||||
"version" => format_crystal_version(
|
||||
context.exec_cmd("crystal", &["--version"])?.stdout.as_str(),
|
||||
)
|
||||
"version" => {
|
||||
let crystal_version =
|
||||
get_crystal_version(&context.exec_cmd("crystal", &["--version"])?.stdout)?;
|
||||
VersionFormatter::format_module_version(
|
||||
module.get_name(),
|
||||
&crystal_version,
|
||||
config.version_format,
|
||||
)
|
||||
}
|
||||
.map(Ok),
|
||||
_ => None,
|
||||
})
|
||||
@@ -50,17 +57,15 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
Some(module)
|
||||
}
|
||||
|
||||
fn format_crystal_version(crystal_version: &str) -> Option<String> {
|
||||
let version = crystal_version
|
||||
// split into ["Crystal", "0.35.1", ...]
|
||||
.split_whitespace()
|
||||
// return "0.35.1"
|
||||
.nth(1)?;
|
||||
|
||||
let mut formatted_version = String::with_capacity(version.len() + 1);
|
||||
formatted_version.push('v');
|
||||
formatted_version.push_str(version);
|
||||
Some(formatted_version)
|
||||
fn get_crystal_version(crystal_version: &str) -> Option<String> {
|
||||
Some(
|
||||
crystal_version
|
||||
// split into ["Crystal", "0.35.1", ...]
|
||||
.split_whitespace()
|
||||
// return "0.35.1"
|
||||
.nth(1)?
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user