do not print infer.py usage message on wrong arguments

Summary:
On wrong arguments (or on no arguments at all), `infer` would spew the error
message of `infer.py`, which makes no sense. Make the python code swallow error
messages and exit with a special code on errors coming from command line
parsing so that the OCaml side is in charge of printing usage messages.

Reviewed By: cristianoc

Differential Revision: D3731594

fbshipit-source-id: fe49cda
master
Jules Villard 8 years ago committed by Facebook Github Bot 5
parent 145cb744f6
commit 0add05de87

@ -78,8 +78,23 @@ def split_args_to_parse():
return (sys_argv[1:dd_index], cmd_raw)
class FailSilentlyArgumentParser(argparse.ArgumentParser):
'''We want to leave the handling of printing usage messages to the
OCaml code. To do so, swallow error messages from ArgumentParser
and exit with a special error code (101) that infer.ml looks for.
'''
def error(self, message):
utils.stderr(message)
utils.stderr('')
exit(22) # in sync with infer.ml
def print_help(self, file=None):
exit(22) # in sync with infer.ml
def create_argparser(parents=[]):
parser = argparse.ArgumentParser(
parser = FailSilentlyArgumentParser(
parents=[analyze.infer_parser] + parents,
add_help=False,
formatter_class=argparse.RawDescriptionHelpFormatter,

@ -104,6 +104,9 @@ let () =
) in
let pid = Unix.create_process args_py.(0) args_py Unix.stdin Unix.stdout Unix.stderr in
let _, status = Unix.waitpid [] pid in
if status = Unix.WEXITED 22 then
(* swallow infer.py argument parsing error *)
Config.print_usage_exit ();
(* collect crashcontext summaries *)
let analysis_is_crashcontext = match Config.analyzer with
| Some Crashcontext -> true

Loading…
Cancel
Save