Use argparse in introspector.

pull/39/merge
Jussi Pakkanen 10 years ago
parent f2de23982e
commit baa0782a22
  1. 2
      meson.py
  2. 25
      mesonintrospect.py

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright 2012-2014 The Meson development team # Copyright 2012-2015 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright 2014 The Meson development team # Copyright 2014-2015 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -23,20 +23,21 @@ project files and don't need this info."""
import json, pickle import json, pickle
import coredata, build, optinterpreter import coredata, build, optinterpreter
from optparse import OptionParser import argparse
import sys, os import sys, os
parser = OptionParser() parser = argparse.ArgumentParser()
parser.add_option('--targets', action='store_true', dest='list_targets', default=False, parser.add_argument('--targets', action='store_true', dest='list_targets', default=False,
help='List top level targets.') help='List top level targets.')
parser.add_option('--target-files', action='store', dest='target_files', default=None, parser.add_argument('--target-files', action='store', dest='target_files', default=None,
help='List source files for a given target.') help='List source files for a given target.')
parser.add_option('--buildsystem-files', action='store_true', dest='buildsystem_files', default=False, parser.add_argument('--buildsystem-files', action='store_true', dest='buildsystem_files', default=False,
help='List files that make up the build system.') help='List files that make up the build system.')
parser.add_option('--buildoptions', action='store_true', dest='buildoptions', default=False, parser.add_argument('--buildoptions', action='store_true', dest='buildoptions', default=False,
help='List all build options.') help='List all build options.')
parser.add_option('--tests', action='store_true', dest='tests', default=False, parser.add_argument('--tests', action='store_true', dest='tests', default=False,
help='List all unit tests.') help='List all unit tests.')
parser.add_argument('args', nargs='+')
def list_targets(coredata, builddata): def list_targets(coredata, builddata):
tlist = [] tlist = []
@ -141,12 +142,12 @@ def list_tests(testdata):
print(json.dumps(result)) print(json.dumps(result))
if __name__ == '__main__': if __name__ == '__main__':
(options, args) = parser.parse_args() options = parser.parse_args()
if len(args) > 1: if len(options.args) > 1:
print('Too many arguments') print('Too many arguments')
sys.exit(1) sys.exit(1)
elif len(args) == 1: elif len(options.args) == 1:
bdir = args[0] bdir = options.args[0]
else: else:
bdir = '' bdir = ''
corefile = os.path.join(bdir, 'meson-private/coredata.dat') corefile = os.path.join(bdir, 'meson-private/coredata.dat')

Loading…
Cancel
Save