1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-29 04:23:26 +00:00

fix: Add disable configuration option to kubernetes module (#491)

This commit is contained in:
Zhenhui Xie 2019-10-05 22:10:16 +08:00 committed by Matan Kushner
parent e5d37e0a97
commit bc9e44f45c
3 changed files with 7 additions and 4 deletions

View File

@ -77,14 +77,14 @@ impl<'a> Context<'a> {
Module::new(name, config)
}
/// Check the `disabled` configuration of the module
pub fn is_module_enabled(&self, name: &str) -> bool {
/// Check if `disabled` option of the module is true in configuration file.
pub fn is_module_disabled_in_config(&self, name: &str) -> bool {
let config = self.config.get_module_config(name);
// 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());
disabled != Some(true)
disabled == Some(true)
}
// returns a new ScanDir struct with reference to current dir_files of context

View File

@ -53,6 +53,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("kubernetes");
let config: KubernetesConfig = KubernetesConfig::try_load(module.config);
if config.disabled {
return None;
};
module.set_style(config.style);
module.get_prefix().set_value(KUBERNETES_PREFIX);

View File

@ -36,7 +36,7 @@ pub fn prompt(args: ArgMatches) {
let modules = &prompt_order
.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
.flatten()
.collect::<Vec<Module>>(); // Remove segments set to `None`