Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_cmdline_parser():
# Were we invoked with `python -m fbs`?
is_python_m_fbs = splitext(basename(sys.argv[0]))[0] == '__main__'
if is_python_m_fbs:
prog = '%s -m fbs' % basename(sys.executable)
else:
prog = None
parser = ArgumentParser(prog=prog, description='fbs')
subparsers = parser.add_subparsers()
for cmd_name, cmd_fn in COMMANDS.items():
cmd_parser = subparsers.add_parser(cmd_name, help=cmd_fn.__doc__)
argspec = getfullargspec(cmd_fn)
args = argspec.args or []
defaults = argspec.defaults or ()
args_without_defaults = args[:1-len(defaults)]
args_with_defaults = args[-len(defaults):]
for arg in args_without_defaults:
cmd_parser.add_argument(arg)
for arg, default in zip(args_with_defaults, defaults):
if not isinstance(default, bool):
raise FbsError(
'Error in command %r: Only booleans are currently '
'supported as optional arguments.' % cmd_name
)
cmd_parser.add_argument(
'--' + arg, action='store_' + str(not default).lower()