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> { + 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 {