piping adaptation
@@ -19,12 +19,19 @@ def add_arguments(parser):
"""
parser.add_argument('-dt', "--datatype", action="store", type=str, dest="datatype", help="Datatype of the input file, e.g., tsv or csv.", default="tsv")
parser.add_argument( "-c", "--columns", action="store", type=str, dest="columns", help="Columns to remove as a comma-separated string, e.g., id,docid")
- parser.add_argument(metavar="input", dest="input", action="store", default=sys.stdin) #, required=True)
+ parser.add_argument('input', nargs='?', action='store') #, action="store", default=sys.stdin) #, required=True)
def run(datatype, columns, input):
# import modules locally
import socket
import sh
- sh.mlr('--tsv', 'cut', '-x', '-f', columns, input, _out=sys.stdout, _err=sys.stderr)
- #sh.mlr('--%s' % datatype, "cut", "-x", '-f', columns, input)
+
+ if input:
+ string = open(input).read()
+ sh.mlr('--tsv', 'cut', '-x', '-f', columns, string, _out=sys.stdout, _err=sys.stderr)
+ elif not sys.stdin.isatty():
+ print('reading from stdin')
+ sh.mlr('--tsv', 'cut', '-x', '-f', columns, _in=sys.stdin, _out=sys.stdout, _err=sys.stderr, _piped=True, _iter=True)
+ else:
+ parser.print_help()
