Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/completion/list_interfaces/list_interfaces.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(*
*)
let intf_type = ref ""
let intf_types = ref []
let broadcast = ref false
let bridgeable = ref false
let bondable = ref false
let no_vlan = ref false

let args = [
("--type", Arg.String (fun s -> intf_type := s), "List interfaces of specified type");
("--type", Arg.String (fun s -> intf_types := (s :: !intf_types)), "List interfaces of specified type");
("--broadcast", Arg.Unit (fun () -> broadcast := true), "List broadcast interfaces");
("--bridgeable", Arg.Unit (fun () -> bridgeable := true), "List bridgeable interfaces");
("--bondable", Arg.Unit (fun () -> bondable := true), "List bondable interfaces");
Expand Down Expand Up @@ -99,8 +99,7 @@ let filter_no_vlan s =
false
with Not_found -> true

let get_interfaces =
let intf_type = !intf_type in
let get_interfaces_by_type out intf_type =
let fltr =
if String.length(intf_type) > 0 then
filter_from_type intf_type
Expand All @@ -124,10 +123,16 @@ let get_interfaces =
if !no_vlan then List.filter filter_no_vlan res
else res
in
let res = List.filter filter_section res in
match fltr with
| Some f -> List.filter f res
| None -> res
let add_out =
let res = List.filter filter_section res in
match fltr with
| Some f -> List.filter f res
| None -> res
in List.append out add_out

let get_interfaces =
let types = List.rev !intf_types in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought: in this implementation, interfaces will appear in the order of the completion helper options. In many cases, our completion outputs are sorted lexicographically, so I wonder if it should also be done here so that --type ethernet --type dummy produces dum0 dum1 eth0 eth1 rather than eth0 eth1 dum0 dum1.

I don't see this as an obstacle for merging this PR, I'm just wondering what behavior we ultimately want here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was considered, and the choice made to leave this in the hands of the user of the completion helper.

List.fold_left get_interfaces_by_type [] types

let () =
let res = get_interfaces in
Expand Down