Skip to content

Commit bc9e44f

Browse files
heyrictmatchai
authored andcommitted
fix: Add disable configuration option to kubernetes module (starship#491)
1 parent e5d37e0 commit bc9e44f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ impl<'a> Context<'a> {
7777
Module::new(name, config)
7878
}
7979

80-
/// Check the `disabled` configuration of the module
81-
pub fn is_module_enabled(&self, name: &str) -> bool {
80+
/// Check if `disabled` option of the module is true in configuration file.
81+
pub fn is_module_disabled_in_config(&self, name: &str) -> bool {
8282
let config = self.config.get_module_config(name);
8383

8484
// If the segment has "disabled" set to "true", don't show it
8585
let disabled = config.and_then(|table| table.as_table()?.get("disabled")?.as_bool());
8686

87-
disabled != Some(true)
87+
disabled == Some(true)
8888
}
8989

9090
// returns a new ScanDir struct with reference to current dir_files of context

src/modules/kubernetes.rs

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
5353

5454
let mut module = context.new_module("kubernetes");
5555
let config: KubernetesConfig = KubernetesConfig::try_load(module.config);
56+
if config.disabled {
57+
return None;
58+
};
5659

5760
module.set_style(config.style);
5861
module.get_prefix().set_value(KUBERNETES_PREFIX);

src/print.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn prompt(args: ArgMatches) {
3636

3737
let modules = &prompt_order
3838
.par_iter()
39-
.filter(|module| context.is_module_enabled(module))
39+
.filter(|module| !context.is_module_disabled_in_config(module))
4040
.map(|module| modules::handle(module, &context)) // Compute modules
4141
.flatten()
4242
.collect::<Vec<Module>>(); // Remove segments set to `None`

0 commit comments

Comments
 (0)