diff --git a/src/modules/golang.rs b/src/modules/golang.rs index 0884a579..325c3394 100644 --- a/src/modules/golang.rs +++ b/src/modules/golang.rs @@ -26,21 +26,16 @@ pub fn module<'a>(context: &'a Context) -> Option> { return None; } - match get_go_version() { - Some(go_version) => { - let mut module = context.new_module("golang"); - let config: GoConfig = GoConfig::try_load(module.config); + let mut module = context.new_module("golang"); + let config: GoConfig = GoConfig::try_load(module.config); - module.set_style(config.style); - module.create_segment("symbol", &config.symbol); + module.set_style(config.style); + module.create_segment("symbol", &config.symbol); - let formatted_version = format_go_version(&go_version)?; - module.create_segment("version", &config.version.with_value(&formatted_version)); + let formatted_version = format_go_version(&get_go_version()?)?; + module.create_segment("version", &config.version.with_value(&formatted_version)); - Some(module) - } - None => None, - } + Some(module) } fn get_go_version() -> Option { @@ -52,6 +47,9 @@ fn get_go_version() -> Option { } fn format_go_version(go_stdout: &str) -> Option { + // go version output looks like this: + // go version go1.13.3 linux/amd64 + let version = go_stdout // split into ["", "1.12.4 linux/amd64"] .splitn(2, "go version go") @@ -62,10 +60,7 @@ fn format_go_version(go_stdout: &str) -> Option { // return "1.12.4" .next()?; - let mut formatted_version = String::with_capacity(version.len() + 1); - formatted_version.push('v'); - formatted_version.push_str(version); - Some(formatted_version) + Some(format!("v{}", version)) } #[cfg(test)]