Skip to content

Commit be99cd2

Browse files
committed
Changelog + minor fixes for #394 / #399.
1 parent 0947e10 commit be99cd2

3 files changed

Lines changed: 21 additions & 18 deletions

File tree

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ Version 3.24
1111

1212
Unreleased
1313

14+
* Add ``--json`` option to the ``list`` CLI commands.
15+
Thanks to `Puneet Dixit`_ for the PR.
16+
(:issue:`394`)
17+
18+
19+
.. _Puneet Dixit: https://github.com/puneetdixit200
20+
1421

1522
Version 3.23
1623
------------

src/reader/_cli.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,7 @@ def list_cmd():
378378

379379

380380
@list_cmd.command()
381-
@click.option(
382-
'--json',
383-
'json_output',
384-
is_flag=True,
385-
help='Output as JSON.',
386-
)
381+
@click.option('--json', 'json_output', is_flag=True, help='Output as JSON.')
387382
@pass_reader
388383
def feeds(reader, json_output):
389384
"""List all the feeds."""
@@ -395,15 +390,16 @@ def feeds(reader, json_output):
395390

396391

397392
@list_cmd.command()
398-
@click.option(
399-
'--json',
400-
'json_output',
401-
is_flag=True,
402-
help='Output as JSON.',
403-
)
393+
@click.option('--json', 'json_output', is_flag=True, help='Output as JSON.')
404394
@pass_reader
405395
def entries(reader, json_output):
406-
"""List all the entries."""
396+
"""List all the entries.
397+
398+
Outputs one line per entry in the following format:
399+
400+
<feed URL> <entry link or id>
401+
402+
"""
407403
for entry in reader.get_entries():
408404
if json_output:
409405
entry = entry._replace(_sequence=None)

tests/test_cli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import json as _json
1+
import json
22
import logging
33
import os
44
import pathlib
@@ -67,7 +67,7 @@ def test_cli(db_path, data_dir, monkeypatch):
6767
expected = {'url_base': url_base, 'rel_base': rel_base}
6868
exec(data_dir.joinpath(feed_filename + '.py').read_text(), expected)
6969

70-
runner = CliRunner() # remove deprecated catch_exceptions argument
70+
runner = CliRunner(catch_exceptions=False)
7171

7272
def invoke(*args):
7373
return runner.invoke(cli, ('--db', db_path, '--feed-root', '') + args)
@@ -119,13 +119,13 @@ def invoke(*args):
119119

120120
result = invoke('list', 'feeds', '--json')
121121
assert result.exit_code == 0
122-
feeds = list(map(_json.loads, result.output.splitlines()))
122+
feeds = list(map(json.loads, result.output.splitlines()))
123123
assert len(feeds) == 1
124124
assert feeds[0]['url'] == feed_path
125125

126126
result = invoke('list', 'entries', '--json')
127127
assert result.exit_code == 0
128-
entries_data = list(map(_json.loads, result.output.splitlines()))
128+
entries_data = list(map(json.loads, result.output.splitlines()))
129129
assert {
130130
(item['feed']['url'], item['link'] or item['id']) for item in entries_data
131131
} == {(feed_path, e.link or e.id) for e in expected['entries']}
@@ -188,7 +188,7 @@ def raise_exception_plugin(thing):
188188
def test_cli_plugin(db_path, monkeypatch, tests_dir):
189189
monkeypatch.syspath_prepend(tests_dir)
190190

191-
runner = CliRunner(catch_exceptions=False)
191+
runner = CliRunner()
192192

193193
with pytest.raises(PluginError):
194194
result = runner.invoke(

0 commit comments

Comments
 (0)