summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShu Kutsuzawa <cappyzawa@yahoo.ne.jp>2021-02-18 02:58:21 +0900
committerGitHub <noreply@github.com>2021-02-17 18:58:21 +0100
commit97fbfffd7e25dc750c6a4602f776cf039cc755e1 (patch)
tree67b1c19c4793c3921e84e26fa08938f4ca6f2a46 /src
parent82c7fd6742add35a795d43977ee6f5bb3e28ea69 (diff)
feat(golang): Configure when the module is shown (#2325)
This makes it possible to configure when the golang module is shown based on the contents of a directory. This should make it possible to be a lot more granular when configuring the module.
Diffstat (limited to 'src')
-rw-r--r--src/configs/go.rs13
-rw-r--r--src/modules/golang.rs27
2 files changed, 18 insertions, 22 deletions
diff --git a/src/configs/go.rs b/src/configs/go.rs
index 7bc77e7ed..b3a1c2a3d 100644
--- a/src/configs/go.rs
+++ b/src/configs/go.rs
@@ -8,6 +8,9 @@ pub struct GoConfig<'a> {
pub symbol: &'a str,
pub style: &'a str,
pub disabled: bool,
+ pub detect_extensions: Vec<&'a str>,
+ pub detect_files: Vec<&'a str>,
+ pub detect_folders: Vec<&'a str>,
}
impl<'a> RootModuleConfig<'a> for GoConfig<'a> {
@@ -17,6 +20,16 @@ impl<'a> RootModuleConfig<'a> for GoConfig<'a> {
symbol: "🐹 ",
style: "bold cyan",
disabled: false,
+ detect_extensions: vec!["go"],
+ detect_files: vec![
+ "go.mod",
+ "go.sum",
+ "glide.yaml",
+ "Gopkg.yml",
+ "Gopkg.lock",
+ ".go-version",
+ ],
+ detect_folders: vec!["Godeps"],
}
}
}
diff --git a/src/modules/golang.rs b/src/modules/golang.rs
index 77aa062f0..662462def 100644
--- a/src/modules/golang.rs
+++ b/src/modules/golang.rs
@@ -4,37 +4,20 @@ use crate::configs::go::GoConfig;
use crate::formatter::StringFormatter;
/// Creates a module with the current Go version
-///
-/// Will display the Go version if any of the following criteria are met:
-/// - Current directory contains a `go.mod` file
-/// - Current directory contains a `go.sum` file
-/// - Current directory contains a `glide.yaml` file
-/// - Current directory contains a `Gopkg.yml` file
-/// - Current directory contains a `Gopkg.lock` file
-/// - Current directory contains a `.go-version` file
-/// - Current directory contains a `Godeps` directory
-/// - Current directory contains a file with the `.go` extension
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
+ let mut module = context.new_module("golang");
+ let config = GoConfig::try_load(module.config);
let is_go_project = context
.try_begin_scan()?
- .set_files(&[
- "go.mod",
- "go.sum",
- "glide.yaml",
- "Gopkg.yml",
- "Gopkg.lock",
- ".go-version",
- ])
- .set_extensions(&["go"])
- .set_folders(&["Godeps"])
+ .set_files(&config.detect_files)
+ .set_extensions(&config.detect_extensions)
+ .set_folders(&config.detect_folders)
.is_match();
if !is_go_project {
return None;
}
- let mut module = context.new_module("golang");
- let config = GoConfig::try_load(module.config);
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|var, _| match var {