Skip to content

Commit

Permalink
Add DocuWiki table output option
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjonbrazil committed Nov 24, 2023
1 parent 5f42c43 commit 69ce9b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 20 additions & 1 deletion jtbl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
__version__ = '1.6.0'
SUCCESS, ERROR = True, False

# START add DocuWiki table format
docuwiki_format = {
"docuwiki": tabulate.TableFormat(
lineabove=tabulate.Line("|", "-", "|", "|"),
linebelowheader=tabulate.Line("|", "-", "|", "|"),
linebetweenrows=None,
linebelow=None,
headerrow=tabulate.DataRow("^", "^", "^"),
datarow=tabulate.DataRow("|", "|", "|"),
padding=1,
with_header_hide=["lineabove"],
)
}
tabulate._table_formats.update(docuwiki_format) # type: ignore
# END add DocuWiki table format

def ctrlc(signum, frame):
"""exit with error on SIGINT"""
Expand All @@ -32,6 +47,7 @@ def helptext():
--cols=n manually configure the terminal width
-c, --csv CSV table output
-d, --docuwiki DocuWiki table output
-f, --fancy fancy table output
-h, --help help
-H, --html HTML table output
Expand Down Expand Up @@ -306,6 +322,7 @@ def main():
long_options[arg[2:]] = None

csv = 'c' in options or 'csv' in long_options
docuwiki = 'd' in options or 'docuwiki' in long_options
html = 'H' in options or 'html' in long_options
markdown = 'm' in options or 'markdown' in long_options
fancy_grid = 'f' in options or 'fancy' in long_options
Expand All @@ -318,14 +335,16 @@ def main():

if markdown:
tbl_fmt = 'github'
elif docuwiki:
tbl_fmt = 'docuwiki'
elif html:
tbl_fmt = 'html'
elif fancy_grid:
tbl_fmt = 'fancy_grid'
else:
tbl_fmt = 'simple'

if not rotate and (markdown or html or csv):
if not rotate and (markdown or docuwiki or html or csv):
nowrap = True

columns = None
Expand Down
4 changes: 3 additions & 1 deletion man/jtbl.1
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ cat data.json | jtbl [OPTIONS]

\fB-c\fP, \fB--csv\fP CSV table output

\fB-h\fP, \fB--help\fP help
\fB-d\fP, \fB--docuwiki\fP DocuWiki table output

\fB-f\fP, \fB--fancy\fP fancy table output

\fB-h\fP, \fB--help\fP help

\fB-H\fP, \fB--html\fP HTML table output

\fB-m\fP, \fB--markdown\fP markdown table output
Expand Down

0 comments on commit 69ce9b0

Please sign in to comment.