summaryrefslogtreecommitdiff
path: root/src/tablib/formats/_cli.py
diff options
context:
space:
mode:
authorDaniel Santos <dfsantosbu@unal.edu.co>2019-12-10 00:04:03 +0100
committerHugo van Kemenade <hugovk@users.noreply.github.com>2019-12-10 01:04:03 +0200
commitfa30ea858d0ac41f2f542e0c50d9f9a2e343deb2 (patch)
tree43b8ec6362e4989a9b6669f82d1e15426d3f5f40 /src/tablib/formats/_cli.py
parent4de2e17984165400bc8aa610ea61c9f441ccbedb (diff)
downloadtablib-fa30ea858d0ac41f2f542e0c50d9f9a2e343deb2.tar.gz
Implement feature that allows to export tabular data suited to a… (#437)
Diffstat (limited to 'src/tablib/formats/_cli.py')
-rw-r--r--src/tablib/formats/_cli.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/tablib/formats/_cli.py b/src/tablib/formats/_cli.py
new file mode 100644
index 0000000..0297ae8
--- /dev/null
+++ b/src/tablib/formats/_cli.py
@@ -0,0 +1,20 @@
+"""Tablib - Command-line Interface table export support.
+
+ Generates a representation for CLI from the dataset.
+ Wrapper for tabulate library.
+"""
+from tabulate import tabulate as Tabulate
+
+
+class CLIFormat:
+ """ Class responsible to export to CLI Format """
+ title = 'cli'
+ DEFAULT_FMT = 'plain'
+
+ @classmethod
+ def export_set(cls, dataset, **kwargs):
+ """Returns CLI representation of a Dataset."""
+ if dataset.headers:
+ kwargs.setdefault('headers', dataset.headers)
+ kwargs.setdefault('tablefmt', cls.DEFAULT_FMT)
+ return Tabulate(dataset, **kwargs)