[CLI] do not generate --command options by default

Summary: This functionality is unused and takes up option names.

Reviewed By: jberdine

Differential Revision: D5182102

fbshipit-source-id: 695913d
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent ddcbb419be
commit 6f0911c157

@ -10,7 +10,7 @@ open! IStd
module CLOpt = CommandLineOption module CLOpt = CommandLineOption
type data = { long: string; command_doc: CLOpt.command_doc } type data = { name: string; command_doc: CLOpt.command_doc }
let inferconfig_env_var = "INFERCONFIG" let inferconfig_env_var = "INFERCONFIG"
@ -19,23 +19,23 @@ let infer_exe_name = "infer"
(** Name of the infer configuration file *) (** Name of the infer configuration file *)
let inferconfig_file = ".inferconfig" let inferconfig_file = ".inferconfig"
let command_to_long = CLOpt.[ let command_to_name = CLOpt.[
Analyze, "analyze"; Capture, "capture"; Compile, "compile"; Report, "report"; Analyze, "analyze"; Capture, "capture"; Compile, "compile"; Report, "report";
ReportDiff, "reportdiff"; Run, "run"; ReportDiff, "reportdiff"; Run, "run";
] ]
let long_of_command = let name_of_command =
List.Assoc.find_exn ~equal:CLOpt.equal_command command_to_long List.Assoc.find_exn ~equal:CLOpt.equal_command command_to_name
let exe_name_of_long long = let exe_name_of_command_name name =
Printf.sprintf "%s-%s" infer_exe_name long Printf.sprintf "%s-%s" infer_exe_name name
let exe_name_of_command cmd = let exe_name_of_command cmd =
long_of_command cmd |> exe_name_of_long name_of_command cmd |> exe_name_of_command_name
let command_of_exe_name exe_name = let command_of_exe_name exe_name =
List.find_map command_to_long ~f:(fun (cmd, long) -> List.find_map command_to_name ~f:(fun (cmd, name) ->
if String.equal exe_name (exe_name_of_long long) then Some cmd if String.equal exe_name (exe_name_of_command_name name) then Some cmd
else None) else None)
let mk_command_doc ~see_also:see_also_commands ?and_also ?environment:environment_opt let mk_command_doc ~see_also:see_also_commands ?and_also ?environment:environment_opt
@ -264,9 +264,9 @@ let run =
let command_to_data = let command_to_data =
let mk cmd mk_doc = let mk cmd mk_doc =
let long = long_of_command cmd in let name = name_of_command cmd in
let command_doc = mk_doc (exe_name_of_command cmd) in let command_doc = mk_doc (exe_name_of_command cmd) in
cmd, { long; command_doc } in cmd, { name; command_doc } in
CLOpt.[mk Analyze analyze; mk Capture capture; mk Compile compile; CLOpt.[mk Analyze analyze; mk Capture capture; mk Compile compile;
mk Report report; mk ReportDiff reportdiff; mk Run run] mk Report report; mk ReportDiff reportdiff; mk Run run]

@ -10,13 +10,13 @@ open! IStd
module CLOpt = CommandLineOption module CLOpt = CommandLineOption
type data = { long: string; command_doc: CLOpt.command_doc } type data = { name: string; command_doc: CLOpt.command_doc }
val infer_exe_name : string val infer_exe_name : string
val inferconfig_env_var : string val inferconfig_env_var : string
val inferconfig_file : string val inferconfig_file : string
val long_of_command : CLOpt.command -> string val name_of_command : CLOpt.command -> string
val exe_name_of_command : CLOpt.command -> string val exe_name_of_command : CLOpt.command -> string
val command_of_exe_name : string -> CLOpt.command option val command_of_exe_name : string -> CLOpt.command option

@ -604,18 +604,25 @@ let mk_rest_actions ?(parse_mode=InferCommand) ?(in_help=[]) doc ~usage decode_a
decode_json = fun ~inferconfig_dir:_ _ -> []} ; decode_json = fun ~inferconfig_dir:_ _ -> []} ;
rest rest
let mk_subcommand command ?on_unknown_arg:(on_unknown=`Reject) ?deprecated ~long ?(name=long) let mk_subcommand command ?on_unknown_arg:(on_unknown=`Reject) ~name ?deprecated_long
?parse_mode ?in_help command_doc = ?parse_mode ?in_help command_doc =
let switch () = let switch () =
curr_command := Some command; curr_command := Some command;
anon_arg_action := {!anon_arg_action with on_unknown} in anon_arg_action := {!anon_arg_action with on_unknown} in
ignore( (match deprecated_long with
mk ?deprecated ~long ~default:() ?parse_mode ?in_help ~meta:"" | Some long ->
(Printf.sprintf "activates the %s subcommand (see $(i,`infer %s --help`))" long long) ignore(
~default_to_string:(fun () -> "") mk ~long ~default:() ?parse_mode ?in_help ~meta:"" ""
~decode_json:(string_json_decoder ~long) ~default_to_string:(fun () -> "")
~mk_setter:(fun _ _ -> switch ()) ~decode_json:(fun ~inferconfig_dir:_ _ ->
~mk_spec:(fun _ -> Unit switch)); raise (Arg.Bad ("Bad option in config file: " ^ long)))
~mk_setter:(fun _ _ ->
warnf "WARNING: '%s' is deprecated. Please use '%s' instead.@\n"
(dashdash long) name;
switch ())
~mk_spec:(fun set -> Unit (fun () -> set "")))
| None -> ()
);
subcommands := (command, (command_doc, name, in_help))::!subcommands; subcommands := (command, (command_doc, name, in_help))::!subcommands;
subcommand_actions := (name, switch)::!subcommand_actions subcommand_actions := (name, switch)::!subcommand_actions

@ -188,14 +188,14 @@ val mk_command_doc : title:string -> section:int -> version:string -> date:strin
string -> command_doc string -> command_doc
(** [mk_subcommand command ~long command_doc] defines the subcommand [command]. A subcommand is (** [mk_subcommand command ~long command_doc] defines the subcommand [command]. A subcommand is
activated by passing [--long], [name], or any [-key] for [key] in [deprecated] on the command activated by passing [name], and by passing [--deprecated_long] if specified. A man page is
line. [name] defaults to [long]. A man page is automatically generated for [command] based on automatically generated for [command] based on the information in [command_doc], if available
the information in [command_doc], if available (otherwise the command is considered internal). (otherwise the command is considered internal). [on_unknown_arg] is the action taken on unknown
[on_unknown_arg] is the action taken on unknown anonymous arguments; it is `Reject by default. anonymous arguments; it is `Reject by default.
*) *)
val mk_subcommand : command -> ?on_unknown_arg:[`Add | `Skip | `Reject] -> val mk_subcommand : command -> ?on_unknown_arg:[`Add | `Skip | `Reject] ->
?deprecated:string list -> long:string -> ?name:string -> name:string -> ?deprecated_long:string -> ?parse_mode:parse_mode ->
?parse_mode:parse_mode -> ?in_help:(command * string) list -> command_doc option -> unit ?in_help:(command * string) list -> command_doc option -> unit
(** environment variable use to pass arguments from parent to child processes *) (** environment variable use to pass arguments from parent to child processes *)
val args_env_var : string val args_env_var : string

@ -356,7 +356,7 @@ let startup_action =
let exe_usage = let exe_usage =
let exe_command_name = match initial_command with let exe_command_name = match initial_command with
| Some CLOpt.Clang -> None (* users cannot see this *) | Some CLOpt.Clang -> None (* users cannot see this *)
| Some command -> Some (CommandDoc.long_of_command command) | Some command -> Some (CommandDoc.name_of_command command)
| None -> None in | None -> None in
Printf.sprintf "%s\nUsage: infer %s [options]\nSee `infer%s --help` for more information." Printf.sprintf "%s\nUsage: infer %s [options]\nSee `infer%s --help` for more information."
version_string (Option.value ~default:"command" exe_command_name) version_string (Option.value ~default:"command" exe_command_name)
@ -397,18 +397,16 @@ let () =
| Clang -> assert false (* filtered out *) | Clang -> assert false (* filtered out *)
| Report -> `Add | Report -> `Add
| Analyze | Capture | Compile | ReportDiff | Run -> `Reject in | Analyze | Capture | Compile | ReportDiff | Run -> `Reject in
let command_deprecated =
List.Assoc.find ~equal:CLOpt.equal_command CLOpt.[ReportDiff, ["-diff"]] in
(* make sure we generate doc for all the commands we know about *) (* make sure we generate doc for all the commands we know about *)
List.filter ~f:(Fn.non (CLOpt.(equal_command Clang))) CLOpt.all_commands List.filter ~f:(Fn.non (CLOpt.(equal_command Clang))) CLOpt.all_commands
|> List.iter ~f:(fun cmd -> |> List.iter ~f:(fun cmd ->
let { CommandDoc.long; command_doc } = CommandDoc.data_of_command cmd in let { CommandDoc.name; command_doc } = CommandDoc.data_of_command cmd in
let on_unknown_arg = on_unknown_arg_from_command cmd in let on_unknown_arg = on_unknown_arg_from_command cmd in
let deprecated = command_deprecated cmd in let deprecated_long = if CLOpt.(equal_command ReportDiff) cmd then Some "diff" else None in
CLOpt.mk_subcommand cmd ~long ~on_unknown_arg ?deprecated (Some command_doc)) CLOpt.mk_subcommand cmd ~name ?deprecated_long ~on_unknown_arg (Some command_doc))
let () = let () =
CLOpt.mk_subcommand CLOpt.Clang ~long:"" ~on_unknown_arg:`Skip None CLOpt.mk_subcommand CLOpt.Clang ~name:"clang" ~on_unknown_arg:`Skip None
let abs_struct = let abs_struct =
CLOpt.mk_int ~deprecated:["absstruct"] ~long:"abs-struct" ~default:1 CLOpt.mk_int ~deprecated:["absstruct"] ~long:"abs-struct" ~default:1

Loading…
Cancel
Save