Skip to content

Commit f59b955

Browse files
Merge pull request #19 from kellyjonbrazil/dev
Dev v1.5.3
2 parents bade6ea + 689b1b8 commit f59b955

File tree

7 files changed

+39
-8
lines changed

7 files changed

+39
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dist/
44
build/
55
*.egg-info/
66
.github/
7+
.vscode/settings.json

CHANGELOG

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
jtbl changelog
22

3+
20231022 v1.5.3
4+
- Add `-f` option for fancy table output
5+
36
20230522 v1.5.2
47
- Fix output for empty array
58

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ $ <JSON Data> | jtbl [OPTIONS]
5555
### Options
5656
- `--cols=n` manually configure the terminal width
5757
- `-c` CSV table output
58+
- `-f` fancy table output
59+
- `-h` help - prints help information
5860
- `-H` HTML table output
5961
- `-m` markdown table output
60-
- `-n` no data wrapping if too long for the terminal width (overrides `--cols` and `-t`)
62+
- `-n` no-wrap - no data wrapping if too long for the terminal width (overrides `--cols` and `-t`)
6163
- `-q` quiet - don't print error messages to STDERR
6264
- `-r` rotate the data (each row turns into a table of key/value pairs)
6365
- `-t` truncate data instead of wrapping if too long for the terminal width
6466
- `-v` prints version information
65-
- `-h` prints help information
6667

6768
## Compatible JSON Formats
6869
`jtbl` works best with a shallow array of JSON objects. Each object should have a few elements that will be turned into table columns. Fortunately, this is how many APIs present their data.

jtbl/cli.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import tabulate
88
import shutil
99

10-
__version__ = '1.5.2'
10+
__version__ = '1.5.3'
1111
SUCCESS, ERROR = True, False
1212

1313

@@ -32,14 +32,15 @@ def helptext():
3232
3333
--cols=n manually configure the terminal width
3434
-c CSV table output
35+
-f fancy table output
36+
-h help
3537
-H HTML table output
3638
-m markdown table output
37-
-n do not try to wrap if too wide for the terminal
39+
-n no-wrap - do not try to wrap if too wide for the terminal
3840
-q quiet - don't print error messages
3941
-r rotate table output
4042
-t truncate data if too wide for the terminal
4143
-v version info
42-
-h help
4344
'''))
4445

4546

@@ -307,6 +308,7 @@ def main():
307308
csv = 'c' in options
308309
html = 'H' in options
309310
markdown = 'm' in options
311+
fancy_grid = 'f' in options
310312
nowrap = 'n' in options
311313
quiet = 'q' in options
312314
rotate = 'r' in options
@@ -318,6 +320,8 @@ def main():
318320
tbl_fmt = 'github'
319321
elif html:
320322
tbl_fmt = 'html'
323+
elif fancy_grid:
324+
tbl_fmt = 'fancy_grid'
321325
else:
322326
tbl_fmt = 'simple'
323327

man/jtbl.1

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH jtbl 1 2023-02-28 1.5.1 "JTBL - JSON tables in the terminal"
1+
.TH jtbl 1 2023-10-22 1.5.3 "JTBL - JSON tables in the terminal"
22
.SH NAME
33
jtbl \- Print JSON and JSON Lines data as a table in the terminal
44
.SH SYNOPSIS
@@ -22,11 +22,15 @@ cat data.json | jtbl [OPTIONS]
2222

2323
\fB-c\fP CSV table output
2424

25+
\fB-h\fP help
26+
27+
\fB-f\fP fancy table output
28+
2529
\fB-H\fP HTML table output
2630

2731
\fB-m\fP markdown table output
2832

29-
\fB-n\fP do not try to wrap if too wide for the terminal
33+
\fB-n\fP no-wrap - do not try to wrap if too wide for the terminal
3034

3135
\fB-q\fP quiet - don't print error messages
3236

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name='jtbl',
8-
version='1.5.2',
8+
version='1.5.3',
99
author='Kelly Brazil',
1010
author_email='[email protected]',
1111
description='A simple cli tool to print JSON and JSON Lines data as a table in the terminal.',

tests/test_make_table.py

+18
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,24 @@ def test_html(self):
495495

496496
self.assertEqual(jtbl.cli.make_table(data=stdin, columns=self.columns, nowrap=True, table_format='html'), (self.SUCCESS, expected))
497497

498+
def test_fancy(self):
499+
"""test fancy output with -f"""
500+
stdin = [{"name":"www.cnn.com.","class":"IN","type":"CNAME","ttl":147,"data":"turner-tls.map.fastly.net."},{"name":"turner-tls.map.fastly.net.","class":"IN","type":"A","ttl":5,"data":"151.101.1.67"},{"name":"turner-tls.map.fastly.net.","class":"IN","type":"A","ttl":5,"data":"151.101.65.67"},{"name":"turner-tls.map.fastly.net.","class":"IN","type":"A","ttl":5,"data":"151.101.129.67"},{"name":"turner-tls.map.fastly.net.","class":"IN","type":"A","ttl":5,"data":"151.101.193.67"}]
501+
expected = textwrap.dedent('''\
502+
╒════════════════════════════╤═════════╤════════╤═══════╤════════════════════════════╕
503+
│ name │ class │ type │ ttl │ data │
504+
╞════════════════════════════╪═════════╪════════╪═══════╪════════════════════════════╡
505+
│ www.cnn.com. │ IN │ CNAME │ 147 │ turner-tls.map.fastly.net. │
506+
├────────────────────────────┼─────────┼────────┼───────┼────────────────────────────┤
507+
│ turner-tls.map.fastly.net. │ IN │ A │ 5 │ 151.101.1.67 │
508+
├────────────────────────────┼─────────┼────────┼───────┼────────────────────────────┤
509+
│ turner-tls.map.fastly.net. │ IN │ A │ 5 │ 151.101.65.67 │
510+
├────────────────────────────┼─────────┼────────┼───────┼────────────────────────────┤
511+
│ turner-tls.map.fastly.net. │ IN │ A │ 5 │ 151.101.129.67 │
512+
├────────────────────────────┼─────────┼────────┼───────┼────────────────────────────┤
513+
│ turner-tls.map.fastly.net. │ IN │ A │ 5 │ 151.101.193.67 │
514+
╘════════════════════════════╧═════════╧════════╧═══════╧════════════════════════════╛''')
515+
self.assertEqual(jtbl.cli.make_table(data=stdin, columns=self.columns, nowrap=True, table_format='fancy_grid'), (self.SUCCESS, expected))
498516

499517
def test_rotate(self):
500518
"""test html output"""

0 commit comments

Comments
 (0)