diff options
author | Thomas O'Donnell <andytom@users.noreply.github.com> | 2021-02-21 19:57:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-21 19:57:09 +0100 |
commit | 64288c2e0437a570f0ff0e6f374f97967bb70ea0 (patch) | |
tree | 5aae8e1ddb1a3efb4143e7e9b3436ef66d34605d | |
parent | c0a209f27ccaf96d08aedc011dca05435fa2c900 (diff) |
feat(java): Configure when the module is shown (#2353)
This makes it possible to configure when the java module is shown
based on the contents of a directory.
-rw-r--r-- | docs/config/README.md | 17 | ||||
-rw-r--r-- | src/configs/java.rs | 14 | ||||
-rw-r--r-- | src/modules/java.rs | 23 |
3 files changed, 30 insertions, 24 deletions
diff --git a/docs/config/README.md b/docs/config/README.md index 8b4682943..400f7039d 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -1362,19 +1362,22 @@ disabled = false ## Java The `java` module shows the currently installed version of Java. -The module will be shown if any of the following conditions are met: +By default the module will be shown if any of the following conditions are met: - The current directory contains a `pom.xml`, `build.gradle.kts`, `build.sbt`, `.java-version`, `.deps.edn`, `project.clj`, or `build.boot` file - The current directory contains a file with the `.java`, `.class`, `.gradle`, `.jar`, `.clj`, or `.cljc` extension ### Options -| Option | Default | Description | -| ---------- | ---------------------------------------- | ----------------------------------------------- | -| `format` | `"via [${symbol}(${version} )]($style)"` | The format for the module. | -| `symbol` | `"☕ "` | A format string representing the symbol of Java | -| `style` | `"red dimmed"` | The style for the module. | -| `disabled` | `false` | Disables the `java` module. | +| Option | Default | Description | +| ------------------- | --------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | +| `format` | `"via [${symbol}(${version} )]($style)"` | The format for the module. | +| `detect_extensions` | `["java", "class", "gradle", "jar", "cljs", "cljc"]` | Which extensions should trigger this module. | +| `detect_files` | `["pom.xml", "build.gradle.kts", "build.sbt", ".java-version", ".deps.edn", "project.clj", "build.boot"]` | Which filenames should trigger this module. | +| `detect_folders` | `[]` | Which folders should trigger this modules. | +| `symbol` | `"☕ "` | A format string representing the symbol of Java | +| `style` | `"red dimmed"` | The style for the module. | +| `disabled` | `false` | Disables the `java` module. | ### Variables diff --git a/src/configs/java.rs b/src/configs/java.rs index 84c178f96..9bbfb5a8a 100644 --- a/src/configs/java.rs +++ b/src/configs/java.rs @@ -8,6 +8,9 @@ pub struct JavaConfig<'a> { pub format: &'a str, pub style: &'a str, pub symbol: &'a str, + pub detect_extensions: Vec<&'a str>, + pub detect_files: Vec<&'a str>, + pub detect_folders: Vec<&'a str>, } impl<'a> RootModuleConfig<'a> for JavaConfig<'a> { @@ -17,6 +20,17 @@ impl<'a> RootModuleConfig<'a> for JavaConfig<'a> { disabled: false, style: "red dimmed", symbol: "☕ ", + detect_extensions: vec!["java", "class", "jar", "gradle", "clj", "cljc"], + detect_files: vec![ + "pom.xml", + "build.gradle.kts", + "build.sbt", + ".java-version", + "deps.edn", + "project.clj", + "build.boot", + ], + detect_folders: vec![], } } } diff --git a/src/modules/java.rs b/src/modules/java.rs index 26745d7d5..36a7abf51 100644 --- a/src/modules/java.rs +++ b/src/modules/java.rs @@ -7,32 +7,21 @@ use regex::Regex; const JAVA_VERSION_PATTERN: &str = "(?P<version>[\\d\\.]+)[^\\s]*\\s(?:built|from)"; /// Creates a module with the current Java version -/// -/// Will display the Java version if any of the following criteria are met: -/// - Current directory contains a file with a `.java`, `.class`, `.jar`, `.gradle`, `.clj`, or `.cljc` extension -/// - Current directory contains a `pom.xml`, `build.gradle.kts`, `build.sbt`, `.java-version`, `deps.edn`, `project.clj`, or `build.boot` file pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { + let mut module = context.new_module("java"); + let config: JavaConfig = JavaConfig::try_load(module.config); + let is_java_project = context .try_begin_scan()? - .set_files(&[ - "pom.xml", - "build.gradle.kts", - "build.sbt", - ".java-version", - "deps.edn", - "project.clj", - "build.boot", - ]) - .set_extensions(&["java", "class", "jar", "gradle", "clj", "cljc"]) + .set_files(&config.detect_files) + .set_extensions(&config.detect_extensions) + .set_folders(&config.detect_folders) .is_match(); if !is_java_project { return None; } - let mut module = context.new_module("java"); - let config: JavaConfig = JavaConfig::try_load(module.config); - let parsed = StringFormatter::new(config.format).and_then(|formatter| { formatter .map_meta(|var, _| match var { |