Mercurial > hg > TextShaper
changeset 19:70dde00a4df0
selectable, albeit single, input
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 23 Feb 2014 00:26:19 -0800 |
parents | df52326aa08d |
children | 09f4c09d9617 |
files | textshaper/main.py |
diffstat | 1 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/textshaper/main.py Sat Feb 22 22:49:18 2014 -0800 +++ b/textshaper/main.py Sun Feb 23 00:26:19 2014 -0800 @@ -12,6 +12,7 @@ import time from which import which + def info(content): """gathers info about the content and returns a dict""" @@ -31,7 +32,11 @@ for key in keys])) def add_options(parser): - """add options to the OptionParser instance""" + """add options to the parser instance""" + + parser.add_option('-f', '--file', dest='input', + type=argparse.FileType('r'), default=sys.stdin, + help="file to read from [DEFAULT: stdin]") if which('xclip'): # TODO: support e.g. xsel or python native parser.add_option('-c', '--clip', '--copy', dest='copy_to_clipboard', @@ -47,7 +52,7 @@ options = parser.parse_args(args) # read from stdin - content = sys.stdin.read() + content = options.read() # print formatted content display(content)