comparison textshaper/main.py @ 22:586631375670

STUB: README.txt textshaper/main.py
author Jeff Hammel <k0scist@gmail.com>
date Sun, 23 Feb 2014 10:10:45 -0800
parents 70dde00a4df0
children 929a5e97af3e
comparison
equal deleted inserted replaced
21:e6f680d25d63 22:586631375670
32 for key in keys])) 32 for key in keys]))
33 33
34 def add_options(parser): 34 def add_options(parser):
35 """add options to the parser instance""" 35 """add options to the parser instance"""
36 36
37 parser.add_option('-f', '--file', dest='input', 37 parser.add_argument('-f', '--file', dest='input',
38 type=argparse.FileType('r'), default=sys.stdin, 38 type=argparse.FileType('r'), default=sys.stdin,
39 help="file to read from [DEFAULT: stdin]") 39 help="file to read from [DEFAULT: stdin]")
40 40
41 if which('xclip'): # TODO: support e.g. xsel or python native 41 if which('xclip'): # TODO: support e.g. xsel or python native
42 parser.add_option('-c', '--clip', '--copy', dest='copy_to_clipboard', 42 parser.add_argument('-c', '--clip', '--copy', dest='copy_to_clipboard',
43 action='store_true', default=False, 43 action='store_true', default=False,
44 help="copy to clipboard") 44 help="copy to clipboard")
45 45
46 46
47 47
48 def main(args=sys.argv[1:]): 48 def main(args=sys.argv[1:]):
49 49
50 # parse command line options 50 # parse command line options
51 parser = argparse.ArgumentParser(description=__doc__, formatter=PlainDescriptionFormatter()) 51 parser = argparse.ArgumentParser(description=__doc__)
52 add_options(parser)
52 options = parser.parse_args(args) 53 options = parser.parse_args(args)
53 54
54 # read from stdin 55 # read input
55 content = options.read() 56 content = options.input.read()
56 57
57 # print formatted content 58 # print formatted content
58 display(content) 59 display(content)
59 60
60 # main display loop 61 # main display loop