learntextvis / textkit

Command line tool for manipulating and analyzing text
MIT License
28 stars 6 forks source link

Make `-` dash not required for piping #25

Closed vlandham closed 8 years ago

vlandham commented 8 years ago

The dash is frequently used in unix commands to refer to standard in/out . But it is really really easy to miss.

If at all possible, it would be great to default to standard in if no input argument is given for many of the functions.

vlandham commented 8 years ago

Preliminary work with the counts function makes me think we can fix this by using:

default=click.open_file('-')

This uses click's open_file helper to open up standard in as the default input. According to the docs, this also autocloses the handle, so there aren't any negative side effects.

the full argument specification would be something like:

@click.argument('tokens', type=click.File('r'), default=click.open_file('-'))

With this in place, both - and non dash piping seems to work fine.

textkit text2words test_data/alice.txt | textkit count --limit 3

",",2418
the,1516
',1127
textkit text2words test_data/alice.txt | textkit count --limit 3 -

",",2418
the,1516
',1127
arnicas commented 8 years ago

Please! The dash annoys me. It feels more unixy to not require it, tbh. Good idea!