style: Clean up Golang module (#612)
This commit is contained in:
parent
f2cb529d1b
commit
e01c41eddf
|
@ -26,21 +26,16 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
match get_go_version() {
|
let mut module = context.new_module("golang");
|
||||||
Some(go_version) => {
|
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.set_style(config.style);
|
||||||
module.create_segment("symbol", &config.symbol);
|
module.create_segment("symbol", &config.symbol);
|
||||||
|
|
||||||
let formatted_version = format_go_version(&go_version)?;
|
let formatted_version = format_go_version(&get_go_version()?)?;
|
||||||
module.create_segment("version", &config.version.with_value(&formatted_version));
|
module.create_segment("version", &config.version.with_value(&formatted_version));
|
||||||
|
|
||||||
Some(module)
|
Some(module)
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_go_version() -> Option<String> {
|
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> {
|
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
|
let version = go_stdout
|
||||||
// split into ["", "1.12.4 linux/amd64"]
|
// split into ["", "1.12.4 linux/amd64"]
|
||||||
.splitn(2, "go version go")
|
.splitn(2, "go version go")
|
||||||
|
@ -62,10 +60,7 @@ fn format_go_version(go_stdout: &str) -> Option<String> {
|
||||||
// return "1.12.4"
|
// return "1.12.4"
|
||||||
.next()?;
|
.next()?;
|
||||||
|
|
||||||
let mut formatted_version = String::with_capacity(version.len() + 1);
|
Some(format!("v{}", version))
|
||||||
formatted_version.push('v');
|
|
||||||
formatted_version.push_str(version);
|
|
||||||
Some(formatted_version)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in New Issue