Skip to content

Commit ec9ca61

Browse files
committed
fix: Prompt the user if additional input is expected in csvjoin, csvsql and csvstack, closes #1169
1 parent 4457f6d commit ec9ca61

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Unreleased
99
* :doc:`/scripts/csvstat` adds a :code:`--non-nulls` option to only output counts of non-null values.
1010
* :doc:`/scripts/csvstat` adds a :code:`--max-precision` option to only output the most decimal places.
1111
* feat: Add a :code:`--null-value` option to commands with the :code:`--blanks` option, to convert additional values to NULL.
12+
* 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`.
1213
* fix: No longer errors if a NUL byte occurs in an input file.
1314
* Add Python 3.12 support.
1415

csvkit/utilities/csvjoin.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env python
22

3+
import sys
4+
35
import agate
46

5-
from csvkit.cli import CSVKitUtility, match_column_identifier
7+
from csvkit.cli import CSVKitUtility, isatty, match_column_identifier
68

79

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

4244
def main(self):
45+
if isatty(sys.stdin) and self.args.input_paths == ['-']:
46+
self.argparser.error('You must provide an input file or piped data.')
47+
4348
self.input_files = []
4449

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

48-
if len(self.input_files) < 1:
49-
self.argparser.error('You must specify at least one file to join.')
50-
5153
if self.args.columns:
5254
join_column_names = self._parse_join_column_names(self.args.columns)
5355

csvkit/utilities/csvsql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def add_arguments(self):
8383
help='Chunk size for batch insert into the table. Requires --insert.')
8484

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

8989
self.input_files = []

csvkit/utilities/csvstack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def add_arguments(self):
4141
help='Use the filename of each input file as its grouping value. When specified, -g will be ignored.')
4242

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

4747
has_groups = self.args.groups is not None or self.args.group_by_filenames

0 commit comments

Comments
 (0)