Skip to content

Commit

Permalink
fix: Prompt the user if additional input is expected in csvjoin, csvs…
Browse files Browse the repository at this point in the history
…ql and csvstack, closes #1169
  • Loading branch information
jpmckinney committed Oct 17, 2023
1 parent 4457f6d commit 367ae92
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -9,6 +9,7 @@ Unreleased
* :doc:`/scripts/csvstat` adds a :code:`--non-nulls` option to only output counts of non-null values.
* :doc:`/scripts/csvstat` adds a :code:`--max-precision` option to only output the most decimal places.
* feat: Add a :code:`--null-value` option to commands with the :code:`--blanks` option, to convert additional values to NULL.
* fix: Prompt the user if additional input is expected (i.e. if no input file or piped data is provided) in :doc:`/scripts/csvjoin`, :doc:`/scripts/csvsql` and :doc:`/scripts/csvstack`.
* fix: No longer errors if a NUL byte occurs in an input file.
* Add Python 3.12 support.

Expand Down
10 changes: 6 additions & 4 deletions csvkit/utilities/csvjoin.py
@@ -1,8 +1,10 @@
#!/usr/bin/env python

import sys

import agate

from csvkit.cli import CSVKitUtility, match_column_identifier
from csvkit.cli import CSVKitUtility, isatty, match_column_identifier


class CSVJoin(CSVKitUtility):
Expand Down Expand Up @@ -40,14 +42,14 @@ def add_arguments(self):
help='Disable type inference when parsing CSV input.')

def main(self):
if isatty(sys.stdin) and self.args.input_paths == ['-']:
sys.stderr.write('No input file or piped data provided. Waiting for standard input:\n')

self.input_files = []

for path in self.args.input_paths:
self.input_files.append(self._open_input_file(path))

if len(self.input_files) < 1:
self.argparser.error('You must specify at least one file to join.')

if self.args.columns:
join_column_names = self._parse_join_column_names(self.args.columns)

Expand Down
2 changes: 1 addition & 1 deletion csvkit/utilities/csvsql.py
Expand Up @@ -83,7 +83,7 @@ def add_arguments(self):
help='Chunk size for batch insert into the table. Requires --insert.')

def main(self):
if isatty(sys.stdin) and not self.args.input_paths:
if isatty(sys.stdin) and self.args.input_paths == ['-']:
self.argparser.error('You must provide an input file or piped data.')

self.input_files = []
Expand Down
2 changes: 1 addition & 1 deletion csvkit/utilities/csvstack.py
Expand Up @@ -41,7 +41,7 @@ def add_arguments(self):
help='Use the filename of each input file as its grouping value. When specified, -g will be ignored.')

def main(self):
if isatty(sys.stdin) and not self.args.input_paths:
if isatty(sys.stdin) and self.args.input_paths == ['-']:
sys.stderr.write('No input file or piped data provided. Waiting for standard input:\n')

has_groups = self.args.groups is not None or self.args.group_by_filenames
Expand Down

0 comments on commit 367ae92

Please sign in to comment.