@@ -71,8 +71,10 @@ def parse_args():
7171 http://github.com/dlenski/wtf''' )
7272 g = p .add_argument_group ("Input/output modes" )
7373 g .add_argument ('inf' , metavar = "textfile" , nargs = '*' , type = argparse .FileType ('rb' ), help = 'Input file(s)' , default = [stdin ])
74- g . add_argument ( '-o' , metavar = "outfile" , dest = 'outf' , type = argparse . FileType ( 'w' ), help = 'Output file (default is stdout)' , default = stdout )
74+
7575 g2 = g .add_mutually_exclusive_group (required = False )
76+ g2 .add_argument ('-o' , metavar = "outfile" , dest = 'outf' , type = argparse .FileType ('w' ), help = 'Output file (default is stdout)' , default = stdout )
77+ g2 .add_argument ('-0' , '--dry-run' , dest = 'outf' , action = 'store_const' , const = open (os .devnull , "w" ), help = "No output" )
7678 g2 .add_argument ('-i' , dest = 'inplace' , action = 'store_const' , const = True , help = 'In-place editing; overwrite each input file with any changes' )
7779 g2 .add_argument ('-I' , dest = 'inplace' , metavar = '.EXT' , help = 'Same, but makes backups with specified extension' )
7880
@@ -102,11 +104,8 @@ def parse_args():
102104 # Check for things that don't make sense
103105 if args .inplace is not None and stdin in args .inf :
104106 p .error ("cannot use stdin for in-place editing (-i/-I); must specify filenames" )
105- elif args .outf != stdout :
106- if args .inplace is not None :
107- p .error ("cannot specify both in-place editing (-i/-I) and output file (-o)" )
108- elif len (args .inf )> 1 :
109- p .error ("cannot specify multiple input files with a single output file (-o)" )
107+ elif args .outf != stdout and len (args .inf )> 1 :
108+ p .error ("cannot specify multiple input files with a single output file (-o)" )
110109
111110 return p , args
112111
0 commit comments