Add possibility to specify input/output filename using positional arguments (e.g. 'scour input.svg output.svg')
This commit is contained in:
parent
ab90d18cb2
commit
72c2ec8e1c
1 changed files with 11 additions and 7 deletions
|
|
@ -3120,11 +3120,10 @@ class HeaderedFormatter(optparse.IndentedHelpFormatter):
|
||||||
# GZ: would prefer this to be in a function or class scope, but tests etc need
|
# GZ: would prefer this to be in a function or class scope, but tests etc need
|
||||||
# access to the defaults anyway
|
# access to the defaults anyway
|
||||||
_options_parser = optparse.OptionParser(
|
_options_parser = optparse.OptionParser(
|
||||||
usage="%prog [-i input.svg] [-o output.svg] [OPTIONS]",
|
usage="%prog [input.svg [output.svg]] [OPTIONS]",
|
||||||
description=("If the input/output files are specified with a svgz"
|
description=("If the input/output files are not specified, stdin/stdout is used. "
|
||||||
" extension, then compressed SVG is assumed. If the input file is not"
|
"If the input/output files are specified with a svgz extension, "
|
||||||
" specified, stdin is used. If the output file is not specified, "
|
"then compressed SVG is assumed."),
|
||||||
" stdout is used."),
|
|
||||||
formatter=HeaderedFormatter(max_help_position=30),
|
formatter=HeaderedFormatter(max_help_position=30),
|
||||||
version=VER)
|
version=VER)
|
||||||
|
|
||||||
|
|
@ -3227,7 +3226,12 @@ def maybe_gziped_file(filename, mode="r"):
|
||||||
def parse_args(args=None, ignore_additional_args=False):
|
def parse_args(args=None, ignore_additional_args=False):
|
||||||
options, rargs = _options_parser.parse_args(args)
|
options, rargs = _options_parser.parse_args(args)
|
||||||
|
|
||||||
if rargs and not ignore_additional_args:
|
if rargs:
|
||||||
|
if not options.infilename:
|
||||||
|
options.infilename = rargs.pop(0)
|
||||||
|
if not options.outfilename and rargs:
|
||||||
|
options.outfilename = rargs.pop(0)
|
||||||
|
if not ignore_additional_args and rargs:
|
||||||
_options_parser.error("Additional arguments not handled: %r, see --help" % rargs)
|
_options_parser.error("Additional arguments not handled: %r, see --help" % rargs)
|
||||||
if options.digits < 0:
|
if options.digits < 0:
|
||||||
_options_parser.error("Can't have negative significant digits, see --help")
|
_options_parser.error("Can't have negative significant digits, see --help")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue