diff --git a/infer/man/man1/infer-debug.txt b/infer/man/man1/infer-debug.txt index e042bdb01..8d732e680 100644 --- a/infer/man/man1/infer-debug.txt +++ b/infer/man/man1/infer-debug.txt @@ -34,8 +34,9 @@ OPTIONS Show this manual with all internal options in the INTERNAL OPTIONS section - --select N - Select option number N. If omitted, prompt for input. + --select (N|all) + Select option number N or all of them. If omitted, prompt for + input. DEBUG GLOBAL TYPE ENVIRONMENT --global-tenv Activates: Print the global type environment. (Conversely: diff --git a/infer/man/man1/infer-explore.txt b/infer/man/man1/infer-explore.txt index 1d9865edf..1e5495e7a 100644 --- a/infer/man/man1/infer-explore.txt +++ b/infer/man/man1/infer-explore.txt @@ -36,8 +36,9 @@ EXPLORE BUGS maximum nesting level are skipped. If omitted, all levels are shown. - --select N - Select option number N. If omitted, prompt for input. + --select (N|all) + Select option number N or all of them. If omitted, prompt for + input. --no-source-preview Deactivates: print code excerpts around trace elements diff --git a/infer/man/man1/infer-full.txt b/infer/man/man1/infer-full.txt index c6b2cc5b2..a2d5da27d 100644 --- a/infer/man/man1/infer-full.txt +++ b/infer/man/man1/infer-full.txt @@ -1048,9 +1048,9 @@ OPTIONS performs better in some circumstances See also infer-analyze(1). - --select N - Select option number N. If omitted, prompt for input. - See also infer-debug(1) and infer-explore(1). + --select (N|all) + Select option number N or all of them. If omitted, prompt for + input. See also infer-debug(1) and infer-explore(1). --no-self-in-block Deactivates: checker self-in-block: An Objective-C-specific diff --git a/infer/man/man1/infer.txt b/infer/man/man1/infer.txt index b9e0addff..415383180 100644 --- a/infer/man/man1/infer.txt +++ b/infer/man/man1/infer.txt @@ -1048,9 +1048,9 @@ OPTIONS performs better in some circumstances See also infer-analyze(1). - --select N - Select option number N. If omitted, prompt for input. - See also infer-debug(1) and infer-explore(1). + --select (N|all) + Select option number N or all of them. If omitted, prompt for + input. See also infer-debug(1) and infer-explore(1). --no-self-in-block Deactivates: checker self-in-block: An Objective-C-specific diff --git a/infer/src/backend/Procedures.ml b/infer/src/backend/Procedures.ml index 523d10315..461fdc33d 100644 --- a/infer/src/backend/Procedures.ml +++ b/infer/src/backend/Procedures.ml @@ -26,12 +26,14 @@ let select_proc_names_interactive ~filter = | [], _ -> F.eprintf "No procedures found" ; None - | _, Some n when n >= proc_names_len -> + | _, Some (`Select n) when n >= proc_names_len -> L.die UserError "Cannot select result #%d out of only %d procedures" n proc_names_len | [proc_name], _ -> F.eprintf "Selected proc name: %a@." Procname.pp proc_name ; Some proc_names - | _, Some n -> + | _, Some `All -> + Some proc_names + | _, Some (`Select n) -> let proc_names_array = List.to_array proc_names in Some [proc_names_array.(n)] | _, None -> diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 91a407348..d1446d01b 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -2070,9 +2070,9 @@ and seconds_per_iteration = and select = - CLOpt.mk_int_opt ~long:"select" ~meta:"N" + CLOpt.mk_string_opt ~long:"select" ~meta:"(N|all)" ~in_help:InferCommand.[(Debug, manual_generic); (Explore, manual_explore_bugs)] - "Select option number $(i,N). If omitted, prompt for input." + "Select option number $(i,N) or $(i,all) of them. If omitted, prompt for input." and scuba_logging, cost_scuba_logging = @@ -3123,7 +3123,17 @@ and scuba_tags = String.Map.map !scuba_tags ~f:(fun v -> String.split v ~on:',') and seconds_per_iteration = !seconds_per_iteration -and select = !select +and select = + match !select with + | None -> + None + | Some "all" -> + Some `All + | Some n -> ( + try Some (`Select (Int.of_string n)) + with _ -> + L.die UserError "Wrong argument for --select: expected an integer or \"all\" but got '%s'" n ) + and show_buckets = !print_buckets diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 8952a8168..861fde995 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -527,7 +527,7 @@ val scuba_tags : string list String.Map.t val seconds_per_iteration : float option -val select : int option +val select : [`All | `Select of int] option val show_buckets : bool diff --git a/infer/src/integration/TraceBugs.ml b/infer/src/integration/TraceBugs.ml index 1798c0055..90c3414f8 100644 --- a/infer/src/integration/TraceBugs.ml +++ b/infer/src/integration/TraceBugs.ml @@ -76,30 +76,30 @@ let read_report report_json = Atdgen_runtime.Util.Json.from_file Jsonbug_j.read_ let explore ~selector_limit ~report_txt:_ ~report_json ~show_source_context ~selected ~max_nested_level = let report = read_report report_json in - let issue_to_display = - match (selected, report) with - | Some n, _ -> ( - (* an issue number has been pre-selected, use that *) - match List.nth report n with - | None -> - L.die UserError "Cannot select issues #%d: only %d issues in '%s'" n (List.length report) - report_json - | Some issue -> - Some (n, issue) ) - | None, [] -> - (* empty report, can't print anything *) - L.progress "No issues found in '%s', exiting.@\n" report_json ; - None - | None, [issue] -> - (* single-issue report: no need to prompt the user to select which issue to display *) - L.progress "Auto-selecting the only issue in '%s'@\n%!" report_json ; - Some (0, issue) - | None, _ :: _ :: _ -> - (* user prompt *) - Some (user_select_issue ~selector_limit report) + let display_issue issue = + L.result "@\n%a" (pp_issue_with_trace ~show_source_context ~max_nested_level) issue in - Option.iter issue_to_display ~f:(fun issue -> - L.result "@\n%a" (pp_issue_with_trace ~show_source_context ~max_nested_level) issue ) + match (selected, report) with + | Some `All, _ -> + List.iteri report ~f:(fun n issue -> display_issue (n, issue)) + | Some (`Select n), _ -> ( + (* an issue number has been pre-selected, use that *) + match List.nth report n with + | None -> + L.die UserError "Cannot select issues #%d: only %d issues in '%s'" n (List.length report) + report_json + | Some issue -> + display_issue (n, issue) ) + | None, [] -> + (* empty report, can't print anything *) + L.progress "No issues found in '%s', exiting.@\n" report_json + | None, [issue] -> + (* single-issue report: no need to prompt the user to select which issue to display *) + L.progress "Auto-selecting the only issue in '%s'@\n%!" report_json ; + display_issue (0, issue) + | None, _ :: _ :: _ -> + (* user prompt *) + display_issue (user_select_issue ~selector_limit report) module GitHub = struct diff --git a/infer/src/integration/TraceBugs.mli b/infer/src/integration/TraceBugs.mli index 655878dc3..f7ebb5a5f 100644 --- a/infer/src/integration/TraceBugs.mli +++ b/infer/src/integration/TraceBugs.mli @@ -11,7 +11,7 @@ val explore : -> report_txt:string -> report_json:string -> show_source_context:bool - -> selected:int option + -> selected:[`All | `Select of int] option -> max_nested_level:int option -> unit