Skip to content

Commit

Permalink
[Config] Support listing sections (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiasli authored Jul 27, 2020
1 parent 148173e commit e9f8a1a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions knack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ def get(self, section, option, fallback=_UNSET):
raise last_ex # pylint:disable=raising-bad-type
return fallback

def sections(self):
combined_sections = []
# Go through the config chain and combine all sections
for config in self._config_file_chain if self.use_local_config else self._config_file_chain[-1:]:
sections = config.sections()
for section in sections:
if section not in combined_sections:
combined_sections.append(section)
return combined_sections

def items(self, section):
import re
pattern = self.env_var_name(section, '.+')
Expand Down Expand Up @@ -174,6 +184,9 @@ def __init__(self, config_dir, config_path, config_comment=None):
def items(self, section):
return self.config_parser.items(section) if self.config_parser else []

def sections(self):
return self.config_parser.sections() if self.config_parser else []

def has_option(self, section, option):
return self.config_parser.has_option(section, option) if self.config_parser else False

Expand Down Expand Up @@ -234,6 +247,3 @@ def clear(self):
for section in self.config_parser.sections():
self.config_parser.remove_section(section)
self.set(self.config_parser)

def sections(self):
return self.config_parser.sections()

0 comments on commit e9f8a1a

Please sign in to comment.