Skip to content

Commit

Permalink
Refactor: Move to default optional parameters when they were reimplem…
Browse files Browse the repository at this point in the history
…ented by hand

Signed-off-by: Andrii Sultanov <[email protected]>
  • Loading branch information
last-genius authored and contificate committed Jul 15, 2024
1 parent a91635e commit 259fb4e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 29 deletions.
6 changes: 3 additions & 3 deletions ocaml/libs/tracing/tracing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ module TracerProvider = struct
get_tracer_providers_unlocked

let set ?enabled ?attributes ?endpoints ~uuid () =
let update_provider (provider : t) enabled attributes endpoints =
let enabled = Option.value ~default:provider.enabled enabled in
let update_provider (provider : t) ?(enabled = provider.enabled) attributes
endpoints =
let attributes : string Attributes.t =
Option.fold ~none:provider.attributes ~some:Attributes.of_list
attributes
Expand All @@ -537,7 +537,7 @@ module TracerProvider = struct
let provider =
match Hashtbl.find_opt tracer_providers uuid with
| Some (provider : t) ->
update_provider provider enabled attributes endpoints
update_provider provider ?enabled attributes endpoints
| None ->
fail "The TracerProvider : %s does not exist" uuid
in
Expand Down
8 changes: 3 additions & 5 deletions ocaml/libs/vhd/vhd_format/f.ml
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,9 @@ module Footer = struct
let create ?(features = []) ~data_offset ?(time_stamp = 0l)
?(creator_application = default_creator_application)
?(creator_version = default_creator_version)
?(creator_host_os = Host_OS.Other 0l) ~current_size ?original_size
~disk_type ?(uid = Uuidm.v `V4) ?(saved_state = false) () =
let original_size =
match original_size with None -> current_size | Some x -> x
in
?(creator_host_os = Host_OS.Other 0l) ~current_size
?(original_size = current_size) ~disk_type ?(uid = Uuidm.v `V4)
?(saved_state = false) () =
let geometry = Geometry.of_sectors Int64.(current_size lsr sector_shift) in
let checksum = 0l in
{
Expand Down
20 changes: 8 additions & 12 deletions ocaml/xapi-idl/lib/typeCombinators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,28 @@ type dict = (string * string) list [@@deriving rpcty]

let option ?name ?(description = []) d =
let open Rpc.Types in
let name =
Option.fold ~none:(Printf.sprintf "%s option" d.name) ~some:Fun.id name
in
let name = Option.value ~default:(Printf.sprintf "%s option" d.name) name in
{name; description; ty= Option d.ty}

let list ?name ?(description = []) d =
let open Rpc.Types in
let name =
Option.fold ~none:(Printf.sprintf "list of %ss" d.name) ~some:Fun.id name
in
let name = Option.value ~default:(Printf.sprintf "list of %ss" d.name) name in
{name; description; ty= List d.ty}

let pair ?name ?(description = []) (p0, p2) =
let open Rpc.Types in
let name =
Option.fold
~none:(Printf.sprintf "pair of %s and %s" p0.name p2.name)
~some:Fun.id name
Option.value
~default:(Printf.sprintf "pair of %s and %s" p0.name p2.name)
name
in
{name; description; ty= Tuple (p0.ty, p2.ty)}

let triple ?name ?(description = []) (p1, p2, p3) =
let open Rpc.Types in
let name =
Option.fold
~none:(Printf.sprintf "triple of %s, %s and %s" p1.name p2.name p3.name)
~some:Fun.id name
Option.value
~default:(Printf.sprintf "triple of %s, %s and %s" p1.name p2.name p3.name)
name
in
{name; description; ty= Tuple3 (p1.ty, p2.ty, p3.ty)}
3 changes: 1 addition & 2 deletions ocaml/xapi/cert_distrib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,12 @@ module WireProtocol = struct
let certificate_file_of_pair (filename, content) = {filename; content}
end

let raise_internal ?e ?details msg : 'a =
let raise_internal ?e ?(details = "") msg : 'a =
let e =
Option.fold ~none:""
~some:(fun e -> e |> Printexc.to_string |> Printf.sprintf "exception: %s")
e
in
let details = Option.value ~default:"" details in
[msg; details; e] |> String.concat ". " |> D.error "%s" ;
raise Api_errors.(Server_error (internal_error, [msg]))

Expand Down
5 changes: 2 additions & 3 deletions ocaml/xapi/workload_balancing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,9 @@ let wlb_request ~__context ~host ~port ~auth ~meth ~params ~handler ~enable_log
| Unix.Unix_error (Unix.ECONNREFUSED, _, _) ->
raise_connection_refused ()

let perform_wlb_request ?auth ?url ?enable_log ~meth ~params ~handle_response
~__context () =
let perform_wlb_request ?auth ?url ?(enable_log = true) ~meth ~params
~handle_response ~__context () =
(* now assumes naming policy of xml repsonses is uniform Envelope->Body-> <x>Response-> <x>Result where <x> is method name *)
let enable_log = match enable_log with Some b -> b | None -> true in
let host, port =
match url with
| Some u ->
Expand Down
3 changes: 1 addition & 2 deletions ocaml/xapi/xapi_mgmt_iface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ let next_server_mode ~mgmt_enabled =

let mgmt_is_enabled () = Server.current_mode () = Any

let run ~__context ?mgmt_enabled () =
let mgmt_enabled = Option.value ~default:(mgmt_is_enabled ()) mgmt_enabled in
let run ~__context ?(mgmt_enabled = mgmt_is_enabled ()) () =
with_lock management_m (fun () ->
Client_certificate_auth_server.update ~__context ~mgmt_enabled ;
next_server_mode ~mgmt_enabled |> Server.update ~__context ;
Expand Down
3 changes: 1 addition & 2 deletions ocaml/xenopsd/xc/service.ml
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,8 @@ module PV_Vnc = struct
| None ->
()

let start ?statefile ~xs ?ip domid =
let start ?statefile ~xs ?(ip = "127.0.0.1") domid =
debug "In PV_Vnc.start" ;
let ip = Option.value ~default:"127.0.0.1" ip in
let l =
[
"-x"
Expand Down

0 comments on commit 259fb4e

Please sign in to comment.