mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Pass command line arguments to main function.
As opposed to reading them from sys.argv. That will facilitate unit testing of main() later.
This commit is contained in:
parent
a68bbeac23
commit
505f7777d4
1 changed files with 10 additions and 10 deletions
20
main.py
20
main.py
|
@ -152,7 +152,7 @@ def ScriptHeader(script, avname):
|
||||||
'//program_version LSL PyOptimizer v' + VERSION + avname
|
'//program_version LSL PyOptimizer v' + VERSION + avname
|
||||||
+ '\n//mono\n\n')
|
+ '\n//mono\n\n')
|
||||||
|
|
||||||
def Usage(about = None):
|
def Usage(progname, about = None):
|
||||||
if about is None:
|
if about is None:
|
||||||
sys.stderr.write(
|
sys.stderr.write(
|
||||||
ur"""LSL optimizer v{version}
|
ur"""LSL optimizer v{version}
|
||||||
|
@ -199,7 +199,7 @@ Preprocessor modes:
|
||||||
Normally, running the preprocessor needs the option 'processpre' active, to
|
Normally, running the preprocessor needs the option 'processpre' active, to
|
||||||
make the output readable by the optimizer. This option is active by default.
|
make the output readable by the optimizer. This option is active by default.
|
||||||
|
|
||||||
""".format(progname=sys.argv[0], version=VERSION))
|
""".format(progname=progname, version=VERSION))
|
||||||
return
|
return
|
||||||
|
|
||||||
if about == 'optimizer-options':
|
if about == 'optimizer-options':
|
||||||
|
@ -298,7 +298,7 @@ Case insensitive.
|
||||||
""")
|
""")
|
||||||
return
|
return
|
||||||
|
|
||||||
def main():
|
def main(argv):
|
||||||
"""Main executable."""
|
"""Main executable."""
|
||||||
|
|
||||||
# If it's good to append the basename to it, it's good to append the
|
# If it's good to append the basename to it, it's good to append the
|
||||||
|
@ -312,13 +312,13 @@ def main():
|
||||||
))
|
))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.gnu_getopt(sys.argv[1:], 'hO:o:p:P:HT',
|
opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HT',
|
||||||
('optimizer-options=', 'help', 'version', 'output=', 'header',
|
('optimizer-options=', 'help', 'version', 'output=', 'header',
|
||||||
'timestamp',
|
'timestamp',
|
||||||
'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow',
|
'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow',
|
||||||
'avid=', 'avname=', 'assetid=', 'scriptname='))
|
'avid=', 'avname=', 'assetid=', 'scriptname='))
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
Usage()
|
Usage(argv[0])
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
outfile = '-'
|
outfile = '-'
|
||||||
|
@ -342,7 +342,7 @@ def main():
|
||||||
|
|
||||||
if opt in ('-O', '--optimizer-options'):
|
if opt in ('-O', '--optimizer-options'):
|
||||||
if arg == 'help':
|
if arg == 'help':
|
||||||
Usage('optimizer-options')
|
Usage(argv[0], 'optimizer-options')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
optchanges = arg.split(',')
|
optchanges = arg.split(',')
|
||||||
|
@ -355,7 +355,7 @@ def main():
|
||||||
options.add(chg[1:].lower())
|
options.add(chg[1:].lower())
|
||||||
|
|
||||||
elif opt in ('-h', '--help'):
|
elif opt in ('-h', '--help'):
|
||||||
Usage()
|
Usage(argv[0])
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
elif opt == '--version':
|
elif opt == '--version':
|
||||||
|
@ -368,7 +368,7 @@ def main():
|
||||||
elif opt in ('-p', '--preproc'):
|
elif opt in ('-p', '--preproc'):
|
||||||
preproc = arg.lower()
|
preproc = arg.lower()
|
||||||
if preproc not in ('ext', 'gcpp', 'mcpp', 'none'):
|
if preproc not in ('ext', 'gcpp', 'mcpp', 'none'):
|
||||||
Usage()
|
Usage(argv[0])
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
mcpp_mode = False
|
mcpp_mode = False
|
||||||
|
@ -431,7 +431,7 @@ def main():
|
||||||
|
|
||||||
fname = args[0] if args else None
|
fname = args[0] if args else None
|
||||||
if fname is None:
|
if fname is None:
|
||||||
Usage()
|
Usage(argv[0])
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
del args
|
del args
|
||||||
|
@ -552,6 +552,6 @@ def main():
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
ret = main()
|
ret = main(sys.argv)
|
||||||
if ret:
|
if ret:
|
||||||
sys.exit(ret)
|
sys.exit(ret)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue