summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas O'Donnell <andytom@users.noreply.github.com>2021-02-21 13:20:14 +0100
committerGitHub <noreply@github.com>2021-02-21 13:20:14 +0100
commit873a005c4203e1359fc8d2d4548c4e8993262fe7 (patch)
tree0efd67d99d09a6799d52275fdd5d87d907719bbf
parent7331e4bec6e0ad18ae29bed9b862d9b345ead67c (diff)
feat(erlang): Configure when the module is shown (#2346)
* feat(erlang): Configure when the module is shown This makes it possible to configure when the erlang 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. * Update docs/config/README.md Co-authored-by: Shu Kutsuzawa <cappyzawa@gmail.com> Co-authored-by: Shu Kutsuzawa <cappyzawa@gmail.com>
-rw-r--r--docs/config/README.md17
-rw-r--r--src/configs/erlang.rs6
-rw-r--r--src/modules/erlang.rs14
3 files changed, 22 insertions, 15 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index b18886251..c52f72fb2 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -944,19 +944,22 @@ default = "unknown shell"
## Erlang
The `erlang` module shows the currently installed version of Erlang/OTP.
-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 `rebar.config` file.
- The current directory contains a `erlang.mk` file.
### Options
-| Option | Default | Description |
-| ---------- | ---------------------------------- | -------------------------------------------------------- |
-| `symbol` | `" "` | The symbol used before displaying the version of erlang. |
-| `style` | `"bold red"` | The style for the module. |
-| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
-| `disabled` | `false` | Disables the `erlang` module. |
+| Option | Default | Description |
+| ------------------- | ------------------------------------ | -------------------------------------------------------- |
+| `symbol` | `" "` | The symbol used before displaying the version of erlang. |
+| `style` | `"bold red"` | The style for the module. |
+| `detect_extensions` | `[]` | Which extensions should trigger this module. |
+| `detect_files` | `["rebar.config", "elang.mk"]` | Which filenames should trigger this module. |
+| `detect_folders` | `[]` | Which folders should trigger this modules. |
+| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
+| `disabled` | `false` | Disables the `erlang` module. |
### Variables
diff --git a/src/configs/erlang.rs b/src/configs/erlang.rs
index 7f4582919..abaecf449 100644
--- a/src/configs/erlang.rs
+++ b/src/configs/erlang.rs
@@ -8,6 +8,9 @@ pub struct ErlangConfig<'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 ErlangConfig<'a> {
@@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for ErlangConfig<'a> {
symbol: " ",
style: "bold red",
disabled: false,
+ detect_extensions: vec![],
+ detect_files: vec!["rebar.config", "erlang.mk"],
+ detect_folders: vec![],
}
}
}
diff --git a/src/modules/erlang.rs b/src/modules/erlang.rs
index 90adf3b84..11e1d6570 100644
--- a/src/modules/erlang.rs
+++ b/src/modules/erlang.rs
@@ -4,23 +4,21 @@ use crate::configs::erlang::ErlangConfig;
use crate::formatter::StringFormatter;
/// Create a module with the current Erlang version
-///
-/// Will display the Erlang version if any of the following criteria are met:
-/// - Current directory contains a rebar.config file
-/// - Current directory contains a erlang.mk file
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
+ let mut module = context.new_module("erlang");
+ let config = ErlangConfig::try_load(module.config);
+
let is_erlang_project = context
.try_begin_scan()?
- .set_files(&["rebar.config", "erlang.mk"])
+ .set_files(&config.detect_files)
+ .set_extensions(&config.detect_extensions)
+ .set_folders(&config.detect_folders)
.is_match();
if !is_erlang_project {
return None;
}
- let mut module = context.new_module("erlang");
- let config = ErlangConfig::try_load(module.config);
-
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|variable, _| match variable {