Skip to content

Commit

Permalink
Add 'reader config dump' command.
Browse files Browse the repository at this point in the history
For #177.
  • Loading branch information
lemon24 committed Aug 20, 2020
1 parent 7bbcec1 commit 48908c0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/reader/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,25 @@ def search_entries(reader, query):
click.echo("{} {}".format(entry.feed.url, entry.link or entry.id))


@cli.group()
def config():
"""Do various things related to config."""


class Dumper(yaml.SafeDumper):
def ignore_aliases(self, data):
return True


@config.command()
@click.option('--merge/--no-merge')
@click.pass_obj
def dump(config, merge):
if merge:
config = config.merge_all()
click.echo(yaml.dump(config.data, sort_keys=False, Dumper=Dumper))


try:
from reader._app.cli import serve

Expand Down
12 changes: 12 additions & 0 deletions src/reader/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def __post_init__(self):
section: self.data.pop(section) for section in unknown_sections
}

# default is always first
for section in list(self.data):
if section != self.default_section:
self.data[section] = self.data.pop(section)

for section in self.sections:
self.data.setdefault(section, {})

Expand All @@ -108,6 +113,13 @@ def merged(self, section, overrides=None):
merge_keys=self.merge_keys,
)

def merge_all(self):
config = copy.deepcopy(self)
for section in list(config.data):
if section != config.default_section:
config.data[section] = config.merged(section)
return config

def make_reader(self, section, **kwargs):
return make_reader_from_config(
**self.merged(section, {'reader': kwargs}).get('reader', {}),
Expand Down

0 comments on commit 48908c0

Please sign in to comment.