Skip to content

Commit

Permalink
Merge pull request #18 from kellyjonbrazil/master
Browse files Browse the repository at this point in the history
Sync to Dev
  • Loading branch information
kellyjonbrazil authored Oct 19, 2023
2 parents 757fb20 + bade6ea commit f43942a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
jtbl changelog

20230522 v1.5.2
- Fix output for empty array

20230228 v1.5.1
- Preserve long float formatting

20230114 v1.5.0
- Be more tolerant of loading JSON Lines with blank lines and whitespace

Expand Down
9 changes: 7 additions & 2 deletions jtbl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import tabulate
import shutil

__version__ = '1.5.0'
__version__ = '1.5.2'
SUCCESS, ERROR = True, False


Expand Down Expand Up @@ -172,6 +172,11 @@ def check_data(data=None, columns=0):

return SUCCESS, data

if data == []:
return SUCCESS, ''

return ERROR, data


def get_headers(data):
"""scan the data and return a dictionary of all of the headers in order"""
Expand Down Expand Up @@ -271,7 +276,7 @@ def make_table(
table_format = 'plain'
headers = ''

return (SUCCESS, tabulate.tabulate(data, headers=headers, tablefmt=table_format))
return (SUCCESS, tabulate.tabulate(data, headers=headers, tablefmt=table_format, floatfmt=''))


def main():
Expand Down
4 changes: 2 additions & 2 deletions man/jtbl.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH jtbl 1 2022-04-04 1.3.1 "JTBL - JSON tables in the terminal"
.TH jtbl 1 2023-02-28 1.5.1 "JTBL - JSON tables in the terminal"
.SH NAME
jtbl \- Print JSON and JSON Lines data as a table in the terminal
.SH SYNOPSIS
Expand Down Expand Up @@ -64,6 +64,6 @@ Kelly Brazil ([email protected])
https://github.com/kellyjonbrazil/jtbl

.SH COPYRIGHT
Copyright (c) 2020-2022 Kelly Brazil
Copyright (c) 2020-2023 Kelly Brazil

License: MIT License
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='jtbl',
version='1.5.0',
version='1.5.2',
author='Kelly Brazil',
author_email='[email protected]',
description='A simple cli tool to print JSON and JSON Lines data as a table in the terminal.',
Expand Down
15 changes: 15 additions & 0 deletions tests/test_make_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ def setUp(self):
self.SUCCESS, self.ERROR = True, False
self.columns = 80

def test_empty_dict(self):
stdin = {}
expected = ''
self.assertEqual(jtbl.cli.make_table(data=stdin, columns=self.columns), (self.SUCCESS, expected))

def test_empty_list(self):
stdin = []
expected = ''
self.assertEqual(jtbl.cli.make_table(data=stdin, columns=self.columns), (self.SUCCESS, expected))

def test_simple_key_value(self):
stdin = [{"key": "value"}]
expected = textwrap.dedent('''\
Expand Down Expand Up @@ -329,6 +339,11 @@ def test_jc_dig_answer(self):

self.assertEqual(jtbl.cli.make_table(data=stdin, columns=80), (self.SUCCESS, expected))

def test_float_format(self):
stdin = [{"a": 1000000, "b": 1000000.1}]
expected = ' a b\n------- ---------\n1000000 1000000.1'

self.assertEqual(jtbl.cli.make_table(data=stdin, columns=80), (self.SUCCESS, expected))

def test_json_lines(self):
"""test JSON Lines data"""
Expand Down

0 comments on commit f43942a

Please sign in to comment.