fix: Add disable configuration option to kubernetes module (#491)
This commit is contained in:
parent
e5d37e0a97
commit
bc9e44f45c
|
@ -77,14 +77,14 @@ impl<'a> Context<'a> {
|
||||||
Module::new(name, config)
|
Module::new(name, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check the `disabled` configuration of the module
|
/// Check if `disabled` option of the module is true in configuration file.
|
||||||
pub fn is_module_enabled(&self, name: &str) -> bool {
|
pub fn is_module_disabled_in_config(&self, name: &str) -> bool {
|
||||||
let config = self.config.get_module_config(name);
|
let config = self.config.get_module_config(name);
|
||||||
|
|
||||||
// If the segment has "disabled" set to "true", don't show it
|
// If the segment has "disabled" set to "true", don't show it
|
||||||
let disabled = config.and_then(|table| table.as_table()?.get("disabled")?.as_bool());
|
let disabled = config.and_then(|table| table.as_table()?.get("disabled")?.as_bool());
|
||||||
|
|
||||||
disabled != Some(true)
|
disabled == Some(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a new ScanDir struct with reference to current dir_files of context
|
// returns a new ScanDir struct with reference to current dir_files of context
|
||||||
|
|
|
@ -53,6 +53,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
|
|
||||||
let mut module = context.new_module("kubernetes");
|
let mut module = context.new_module("kubernetes");
|
||||||
let config: KubernetesConfig = KubernetesConfig::try_load(module.config);
|
let config: KubernetesConfig = KubernetesConfig::try_load(module.config);
|
||||||
|
if config.disabled {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
|
||||||
module.set_style(config.style);
|
module.set_style(config.style);
|
||||||
module.get_prefix().set_value(KUBERNETES_PREFIX);
|
module.get_prefix().set_value(KUBERNETES_PREFIX);
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub fn prompt(args: ArgMatches) {
|
||||||
|
|
||||||
let modules = &prompt_order
|
let modules = &prompt_order
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.filter(|module| context.is_module_enabled(module))
|
.filter(|module| !context.is_module_disabled_in_config(module))
|
||||||
.map(|module| modules::handle(module, &context)) // Compute modules
|
.map(|module| modules::handle(module, &context)) // Compute modules
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect::<Vec<Module>>(); // Remove segments set to `None`
|
.collect::<Vec<Module>>(); // Remove segments set to `None`
|
||||||
|
|
Loading…
Reference in New Issue