Skip to content

Commit e01c41e

Browse files
matiaskotlikmatchai
authored andcommitted
style: Clean up Golang module (starship#612)
1 parent f2cb529 commit e01c41e

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/modules/golang.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,16 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
2626
return None;
2727
}
2828

29-
match get_go_version() {
30-
Some(go_version) => {
31-
let mut module = context.new_module("golang");
32-
let config: GoConfig = GoConfig::try_load(module.config);
29+
let mut module = context.new_module("golang");
30+
let config: GoConfig = GoConfig::try_load(module.config);
3331

34-
module.set_style(config.style);
35-
module.create_segment("symbol", &config.symbol);
32+
module.set_style(config.style);
33+
module.create_segment("symbol", &config.symbol);
3634

37-
let formatted_version = format_go_version(&go_version)?;
38-
module.create_segment("version", &config.version.with_value(&formatted_version));
35+
let formatted_version = format_go_version(&get_go_version()?)?;
36+
module.create_segment("version", &config.version.with_value(&formatted_version));
3937

40-
Some(module)
41-
}
42-
None => None,
43-
}
38+
Some(module)
4439
}
4540

4641
fn get_go_version() -> Option<String> {
@@ -52,6 +47,9 @@ fn get_go_version() -> Option<String> {
5247
}
5348

5449
fn format_go_version(go_stdout: &str) -> Option<String> {
50+
// go version output looks like this:
51+
// go version go1.13.3 linux/amd64
52+
5553
let version = go_stdout
5654
// split into ["", "1.12.4 linux/amd64"]
5755
.splitn(2, "go version go")
@@ -62,10 +60,7 @@ fn format_go_version(go_stdout: &str) -> Option<String> {
6260
// return "1.12.4"
6361
.next()?;
6462

65-
let mut formatted_version = String::with_capacity(version.len() + 1);
66-
formatted_version.push('v');
67-
formatted_version.push_str(version);
68-
Some(formatted_version)
63+
Some(format!("v{}", version))
6964
}
7065

7166
#[cfg(test)]

0 commit comments

Comments
 (0)