diff options
author | zlg <zlg@zlg.space> | 2018-09-29 23:27:05 -0700 |
---|---|---|
committer | zlg <zlg@zlg.space> | 2018-09-29 23:34:35 -0700 |
commit | 7288560c5678991527c7b2c2ed0d7f3979f70c67 (patch) | |
tree | 00ee2e3a79cf1aae646d9c9b44df6c1fcac4325c /src/vgstash | |
parent | setup.py: Bump to alpha4 for PyPI (diff) | |
download | vgstash-7288560c5678991527c7b2c2ed0d7f3979f70c67.tar.gz vgstash-7288560c5678991527c7b2c2ed0d7f3979f70c67.tar.bz2 vgstash-7288560c5678991527c7b2c2ed0d7f3979f70c67.tar.xz vgstash-7288560c5678991527c7b2c2ed0d7f3979f70c67.zip |
cli: Add pretty printing to 'list' command
Also add the "--width" option to specify the maximum width of the table.
Diffstat (limited to 'src/vgstash')
-rwxr-xr-x | src/vgstash/__init__.py | 24 | ||||
-rw-r--r-- | src/vgstash/test_vgstash_cli.py | 50 |
2 files changed, 61 insertions, 13 deletions
diff --git a/src/vgstash/__init__.py b/src/vgstash/__init__.py index 71b5981..798a062 100755 --- a/src/vgstash/__init__.py +++ b/src/vgstash/__init__.py @@ -33,18 +33,18 @@ DEFAULT_CONFIG = { } FILTERS = { - 'allgames': "SELECT * FROM games ORDER BY system, title", - 'backlog': "SELECT * FROM games WHERE ownership > 0 AND progress < 3 ORDER BY system, title ASC", - 'borrowing': "SELECT * FROM games WHERE ownership = 0 AND progress = 2 ORDER BY system, title ASC", - 'complete': "SELECT * FROM games WHERE progress = 4 ORDER BY system, title ASC", - 'digital': "SELECT * FROM games WHERE ownership = 2 ORDER BY system, title ASC", - 'done': "SELECT * FROM games WHERE progress > 2 ORDER BY system, title ASC", - 'incomplete': "SELECT * FROM games WHERE progress = 3 AND ownership > 0 ORDER BY system, title ASC", - 'new': "SELECT * FROM games WHERE progress = 1 ORDER BY system, title ASC", - 'owned': "SELECT * FROM games WHERE ownership > 0 ORDER BY system, title ASC", - 'physical': "SELECT * FROM games WHERE ownership = 1 ORDER BY system, title ASC", - 'playlog': "SELECT * FROM games WHERE ownership > 0 AND progress = 2 ORDER BY system, title ASC", - 'unowned': "SELECT * FROM games WHERE ownership = 0 ORDER BY system, title ASC", + 'allgames': "SELECT rowid,* FROM games ORDER BY system, title", + 'backlog': "SELECT rowid,* FROM games WHERE ownership > 0 AND progress < 3 ORDER BY system, title ASC", + 'borrowing': "SELECT rowid,* FROM games WHERE ownership = 0 AND progress = 2 ORDER BY system, title ASC", + 'complete': "SELECT rowid,* FROM games WHERE progress = 4 ORDER BY system, title ASC", + 'digital': "SELECT rowid,* FROM games WHERE ownership = 2 ORDER BY system, title ASC", + 'done': "SELECT rowid,* FROM games WHERE progress > 2 ORDER BY system, title ASC", + 'incomplete': "SELECT rowid,* FROM games WHERE progress = 3 AND ownership > 0 ORDER BY system, title ASC", + 'new': "SELECT rowid,* FROM games WHERE progress = 1 ORDER BY system, title ASC", + 'owned': "SELECT rowid,* FROM games WHERE ownership > 0 ORDER BY system, title ASC", + 'physical': "SELECT rowid,* FROM games WHERE ownership = 1 ORDER BY system, title ASC", + 'playlog': "SELECT rowid,* FROM games WHERE ownership > 0 AND progress = 2 ORDER BY system, title ASC", + 'unowned': "SELECT rowid,* FROM games WHERE ownership = 0 ORDER BY system, title ASC", } def kvmatch(arg, dict_map, fallback): diff --git a/src/vgstash/test_vgstash_cli.py b/src/vgstash/test_vgstash_cli.py index 3ad661d..d0def8b 100644 --- a/src/vgstash/test_vgstash_cli.py +++ b/src/vgstash/test_vgstash_cli.py @@ -6,7 +6,7 @@ import vgstash_cli from click.testing import CliRunner -verbose = False +verbose = True def test_init(): runner = CliRunner() @@ -81,3 +81,51 @@ def test_list_filter(): 'Super Mario Bros.|NES|1|2|', 'The Legend of Zelda|NES|2|2|\n', )) + +def test_list_pretty(): + runner = CliRunner() + result = runner.invoke(vgstash_cli.cli, ['list', '-w', '80']) + if verbose: + print(result.output) + assert result.exit_code == 0 + assert result.output == '\n'.join(( + ' ID | Title | System | Own | Status ', + '--------------------------------------------------------------------------------', + ' 3 | Sonic the Hedgehog 2 | Genesis | | C', + ' 4 | Vectorman | Genesis | | C', + ' 5 | Vectorman 2 | Genesis | P | B ', + ' 1 | Super Mario Bros. | NES | P | B ', + ' 2 | The Legend of Zelda | NES | D | B \n' + )) + +def test_list_pretty_smaller(): + runner = CliRunner() + result = runner.invoke(vgstash_cli.cli, ['list', '-w', '60']) + if verbose: + print(result.output) + assert result.exit_code == 0 + assert result.output == '\n'.join(( + ' ID | Title | System | Own | Status ', + '------------------------------------------------------------', + ' 3 | Sonic the Hedgehog 2 | Genesis | | C', + ' 4 | Vectorman | Genesis | | C', + ' 5 | Vectorman 2 | Genesis | P | B ', + ' 1 | Super Mario Bros. | NES | P | B ', + ' 2 | The Legend of Zelda | NES | D | B \n' + )) + +def test_list_pretty_tiny(): + runner = CliRunner() + result = runner.invoke(vgstash_cli.cli, ['list', '-w', '50']) + if verbose: + print(result.output) + assert result.exit_code == 0 + assert result.output == '\n'.join(( + ' ID | Title | System | Own | Status ', + '--------------------------------------------------', + ' 3 | Sonic the Hedge | Genesis | | C', + ' 4 | Vectorman | Genesis | | C', + ' 5 | Vectorman 2 | Genesis | P | B ', + ' 1 | Super Mario Bro | NES | P | B ', + ' 2 | The Legend of Z | NES | D | B \n' + )) |