Skip to content

Commit a2690b0

Browse files
committed
Fix bash completion for booleans
Broken by PR #1705. Completing "--enable" crashes with "files[+]" not found.
1 parent 03c3269 commit a2690b0

2 files changed

Lines changed: 16 additions & 19 deletions

File tree

src/config/options.ml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,31 @@ let () =
1616
(* Yojson.Safe.pretty_to_channel (Stdlib.open_out "options.defaults.json") defaults; *)
1717
()
1818

19-
let rec element_paths (element: element): string list =
20-
match element.kind with
21-
| String _
22-
| Boolean
23-
| Integer _
24-
| Number _ ->
19+
let rec element_paths ~bool (element: element): string list =
20+
match element.kind, bool with
21+
| String _, false
22+
| Boolean, _
23+
| Integer _, false
24+
| Number _, false ->
2525
[""]
26-
| Monomorphic_array _ ->
26+
| Monomorphic_array _, false ->
2727
[""; "[+]"; "[-]"; "[*]"]
28-
| Object object_specs ->
28+
| Object object_specs, _ ->
2929
List.concat_map (fun (name, field_element, _, _) ->
30-
List.map (fun path -> "." ^ name ^ path) (element_paths field_element)
30+
List.map (fun path -> "." ^ name ^ path) (element_paths ~bool field_element)
3131
) object_specs.properties
32+
| _, true ->
33+
[]
3234
| _ ->
3335
Logs.Format.error "%a" Json_schema.pp (create element);
3436
failwith "element_paths"
3537

36-
let schema_paths (schema: schema): string list =
37-
element_paths (root schema)
38+
let schema_paths ~bool (schema: schema): string list =
39+
element_paths ~bool (root schema)
3840
|> List.map BatString.lchop (* remove first '.' *)
3941

40-
let paths = schema_paths schema
42+
let paths = schema_paths ~bool:false schema
43+
let bool_paths = schema_paths ~bool:true schema
4144

4245
let rec element_completions (element: element): (string * string list) list =
4346
let default_completion () =

src/maingoblint.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,7 @@ let rec option_spec_list: Arg_complete.speclist Lazy.t = lazy (
8888
Arg_complete.strings Options.paths s
8989
in
9090
let complete_bool_option s =
91-
let cs = complete_option s in
92-
let is_bool c =
93-
match GobConfig.get_json c with
94-
| `Bool _ -> true
95-
| _ -> false
96-
in
97-
List.filter is_bool cs
91+
Arg_complete.strings Options.bool_paths s
9892
in
9993
let complete_last_option_value s =
10094
complete_option_value !last_complete_option s

0 commit comments

Comments
 (0)