summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatias Kotlik <mdkotlik@gmail.com>2019-10-31 20:53:28 -0500
committerMatan Kushner <hello@matchai.me>2019-11-01 10:53:28 +0900
commite01c41eddf0749583ed875ada92d3f08d2782c62 (patch)
tree6ce7c9021e6071bc068285f54c5ade78c80b2711
parentf2cb529d1bd44f996ad60c2d27ae14d1f9ad44ba (diff)
style: Clean up Golang module (#612)
-rw-r--r--src/modules/golang.rs27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/modules/golang.rs b/src/modules/golang.rs
index 0884a5791..325c3394a 100644
--- a/src/modules/golang.rs
+++ b/src/modules/golang.rs
@@ -26,21 +26,16 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
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<String> {
@@ -52,6 +47,9 @@ fn get_go_version() -> Option<String> {
}
fn format_go_version(go_stdout: &str) -> Option<String> {
+ // 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<String> {
// 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)]