Skip to content

Commit

Permalink
feat(csvformat): Add a --out-asv option, closes #1232
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Feb 15, 2024
1 parent 6a10a4e commit 23f8abf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Unreleased
----------

* feat: :doc:`/scripts/csvformat` adds a :code:`--out-asv` (:code:`--A`) option to use the ASCII unit separator and record separator.

1.4.0 - February 13, 2024
-------------------------

Expand Down
15 changes: 13 additions & 2 deletions csvkit/utilities/csvformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def add_arguments(self):
self.argparser.add_argument(
'-T', '--out-tabs', dest='out_tabs', action='store_true',
help='Specify that the output file is delimited with tabs. Overrides "-D".')
self.argparser.add_argument(
'-A', '--out-asv', dest='out_asv', action='store_true',
help='Specify that the output file is delimited with the ASCII unit separator and record separator. '
'Overrides "-T", "-D" and "-M".')
self.argparser.add_argument(
'-Q', '--out-quotechar', dest='out_quotechar',
help='Character used to quote strings in the output file.')
Expand All @@ -45,12 +49,19 @@ def _extract_csv_writer_kwargs(self):
if self.args.line_numbers:
kwargs['line_numbers'] = True

if self.args.out_tabs:
if self.args.out_asv:
kwargs['delimiter'] = '\x1f'
elif self.args.out_tabs:
kwargs['delimiter'] = '\t'
elif self.args.out_delimiter:
kwargs['delimiter'] = self.args.out_delimiter

for arg in ('quotechar', 'quoting', 'doublequote', 'escapechar', 'lineterminator'):
if self.args.out_asv:
kwargs['lineterminator'] = '\x1e'
elif self.args.out_lineterminator:
kwargs['lineterminator'] = self.args.out_lineterminator

for arg in ('quotechar', 'quoting', 'doublequote', 'escapechar'):
value = getattr(self.args, f'out_{arg}')
if value is not None:
kwargs[arg] = value
Expand Down

0 comments on commit 23f8abf

Please sign in to comment.