diff options
author | David Knaack <davidkna@users.noreply.github.com> | 2021-02-15 20:21:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-15 20:21:21 +0100 |
commit | 856610d53b140f5ab799341ad97b156883b21d65 (patch) | |
tree | d88baafd60c5806fbac32fc4185bd826379e89b2 /src | |
parent | 6bd4e724e9fdddd355540bf25ff7ae8fea9e3ed6 (diff) |
feat(vagrant): Configure when the module is shown (#2314)
* feat(vagrant): Configure when the module is shown
This makes it possible to configure when the vagrant module is shown based on the contents of a directory.
* fix documentation
Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/configs/vagrant.rs | 6 | ||||
-rw-r--r-- | src/modules/vagrant.rs | 12 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/configs/vagrant.rs b/src/configs/vagrant.rs index cab83c01f..94403bb19 100644 --- a/src/configs/vagrant.rs +++ b/src/configs/vagrant.rs @@ -8,6 +8,9 @@ pub struct VagrantConfig<'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 VagrantConfig<'a> { @@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for VagrantConfig<'a> { symbol: "⍱ ", style: "cyan bold", disabled: false, + detect_extensions: vec![], + detect_files: vec!["Vagrantfile"], + detect_folders: vec![], } } } diff --git a/src/modules/vagrant.rs b/src/modules/vagrant.rs index 99f8bd6a0..06ebef75b 100644 --- a/src/modules/vagrant.rs +++ b/src/modules/vagrant.rs @@ -4,21 +4,21 @@ use crate::configs::vagrant::VagrantConfig; use crate::formatter::StringFormatter; /// Creates a module with the current Vagrant version -/// -/// Will display the Vagrant version if any of the following criteria are met: -/// - Current directory contains a `Vagrantfile` file pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { + let mut module = context.new_module("vagrant"); + let config = VagrantConfig::try_load(module.config); + let is_vagrant_project = context .try_begin_scan()? - .set_files(&["Vagrantfile"]) + .set_files(&config.detect_files) + .set_extensions(&config.detect_extensions) + .set_folders(&config.detect_folders) .is_match(); if !is_vagrant_project { return None; } - let mut module = context.new_module("vagrant"); - let config = VagrantConfig::try_load(module.config); let parsed = StringFormatter::new(config.format).and_then(|formatter| { formatter .map_meta(|var, _| match var { |