Provides some standard arguments: --debug, --option, --shell-quoted-option
Then, calls `add_args_fn(parser)` to add application-specific arguments.
`opts` are first used as defaults for the various command-line
arguments. Then, the parsed arguments are mapped back into `opts`,
which then become the values for `FBCodeBuilder.option()`, to be used
both by the builder and by `get_steps_fn()`.
`help` is printed in response to the `--help` argument.
Definition at line 15 of file parse_args.py.
References folly.format(), and shell_quoting.raw_shell().
Referenced by make_docker_context.make_docker_context().
18 Provides some standard arguments: --debug, --option, --shell-quoted-option 20 Then, calls `add_args_fn(parser)` to add application-specific arguments. 22 `opts` are first used as defaults for the various command-line 23 arguments. Then, the parsed arguments are mapped back into `opts`, 24 which then become the values for `FBCodeBuilder.option()`, to be used 25 both by the builder and by `get_steps_fn()`. 27 `help` is printed in response to the `--help` argument. 30 top_level_opts =
set(top_level_opts)
32 parser = argparse.ArgumentParser(
34 formatter_class=argparse.RawDescriptionHelpFormatter
40 '--option', nargs=2, metavar=(
'KEY',
'VALUE'), action=
'append',
42 (k, v)
for k, v
in opts.items()
43 if k
not in top_level_opts
and not isinstance(v, ShellQuoted)
45 help=
'Set project-specific options. These are assumed to be raw ' 46 'strings, to be shell-escaped as needed. Default: %(default)s.',
49 '--shell-quoted-option', nargs=2, metavar=(
'KEY',
'VALUE'),
52 (k,
raw_shell(v))
for k, v
in opts.items()
53 if k
not in top_level_opts
and isinstance(v, ShellQuoted)
55 help=
'Set project-specific options. These are assumed to be shell-' 56 'quoted, and may be used in commands as-is. Default: %(default)s.',
59 parser.add_argument(
'--debug', action=
'store_true', help=
'Log more')
60 args = parser.parse_args()
63 level=logging.DEBUG
if args.debug
else logging.INFO,
64 format=
'%(levelname)s: %(message)s' 68 logging.debug(
'opts before command-line arguments: {0}'.
format(opts))
71 for key
in top_level_opts:
72 val = getattr(args, key)
76 for key, val
in args.option:
78 for key, val
in args.shell_quoted_option:
81 logging.debug(
'opts after command-line arguments: {0}'.
format(new_opts))
84
def parse_args_to_fbcode_builder_opts(add_args_fn, top_level_opts, opts, help)
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)