comparison textshaper/indent.py @ 26:c23782a7b7ba

more hookups, yo
author Jeff Hammel <k0scist@gmail.com>
date Sun, 23 Feb 2014 11:41:37 -0800
parents 0930c6884f8a
children 23616399f36c
comparison
equal deleted inserted replaced
25:a43d0ad17c29 26:c23782a7b7ba
46 parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), 46 parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),
47 default=sys.stdin) 47 default=sys.stdin)
48 parser.add_argument('-o', '--output', dest='output', 48 parser.add_argument('-o', '--output', dest='output',
49 help="output file or stdout if not given") 49 help="output file or stdout if not given")
50 50
51
51 def main(args=sys.argv[1:]): 52 def main(args=sys.argv[1:]):
52 53
53 # parse command line 54 # parse command line
54 description = """indent files or stdin if no files given""" 55 description = """indent files or stdin if no files given"""
55 parser = argparse.Argument(description=__doc__) 56 parser = argparse.Argument(description=__doc__)
58 59
59 # process input 60 # process input
60 for f in _files(): 61 for f in _files():
61 62
62 # indent the text 63 # indent the text
63 indented = indent(f) 64 indented = '\n'.join(indent(f))
64 65
65 # append to output 66 # append to output
66 if options.output: 67 if options.output:
67 with open(options.output, 'a') as f: 68 with open(options.output, 'a') as f:
68 f.write(indented) 69 f.write(indented)