summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas O'Donnell <andytom@users.noreply.github.com>2021-02-13 11:38:47 +0100
committerGitHub <noreply@github.com>2021-02-13 11:38:47 +0100
commit47a769cdf85d6f42250fe179e482ca40647bb2d8 (patch)
tree4e56e0485352180e8e91e6698b76f80b8a5e889e /src
parenteccbda8328159adbb261112cba285d1f63ae29e7 (diff)
feat(cmake): Configure when the module is shown (#2280)
This makes it possible to configure when the cmake 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/cmake.rs6
-rw-r--r--src/modules/cmake.rs12
2 files changed, 12 insertions, 6 deletions
diff --git a/src/configs/cmake.rs b/src/configs/cmake.rs
index 58c69d423..1fc934f4a 100644
--- a/src/configs/cmake.rs
+++ b/src/configs/cmake.rs
@@ -8,6 +8,9 @@ pub struct CMakeConfig<'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 CMakeConfig<'a> {
@@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for CMakeConfig<'a> {
symbol: "喝 ",
style: "bold blue",
disabled: false,
+ detect_extensions: vec![],
+ detect_files: vec!["CMakeLists.txt", "CMakeCache.txt"],
+ detect_folders: vec![],
}
}
}
diff --git a/src/modules/cmake.rs b/src/modules/cmake.rs
index 638b7d727..2d003a977 100644
--- a/src/modules/cmake.rs
+++ b/src/modules/cmake.rs
@@ -4,21 +4,21 @@ use crate::configs::cmake::CMakeConfig;
use crate::formatter::StringFormatter;
/// Creates a module with the current CMake version
-///
-/// Will display the CMake version if any of the following criteria are met:
-/// - The current directory contains a `CMakeLists.txt` or `CMakeCache.txt`
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
+ let mut module = context.new_module("cmake");
+ let config = CMakeConfig::try_load(module.config);
+
let is_cmake_project = context
.try_begin_scan()?
- .set_files(&["CMakeLists.txt", "CMakeCache.txt"])
+ .set_files(&config.detect_files)
+ .set_extensions(&config.detect_extensions)
+ .set_folders(&config.detect_folders)
.is_match();
if !is_cmake_project {
return None;
}
- let mut module = context.new_module("cmake");
- let config = CMakeConfig::try_load(module.config);
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|variable, _| match variable {