From 7d690bd3c1f145a1a73609adf83992a053480e17 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 29 Sep 2020 12:00:40 -0700 Subject: [PATCH] _ Signed-off-by: Rudi Grinberg --- src/dune_engine/package.ml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/dune_engine/package.ml b/src/dune_engine/package.ml index d670684e88c4..88990d04aac6 100644 --- a/src/dune_engine/package.ml +++ b/src/dune_engine/package.ml @@ -231,8 +231,10 @@ module Source_kind = struct | Bitbucket | Gitlab - let kind_string_map = - [ (Github, "github"); (Bitbucket, "bitbucket"); (Gitlab, "gitlab") ] + let to_string = function + | Github -> "github" + | Bitbucket -> "bitbucket" + | Gitlab -> "gitlab" type t = { user : string @@ -240,8 +242,7 @@ module Source_kind = struct ; kind : kind } - let dyn_of_kind kind = - List.assoc kind_string_map kind |> Option.value_exn |> Dyn.Encoder.string + let dyn_of_kind kind = kind |> to_string |> Dyn.Encoder.string let to_dyn { user; repo; kind } = let open Dyn.Encoder in @@ -256,9 +257,6 @@ module Source_kind = struct | Bitbucket -> "bitbucket.org" | Gitlab -> "gitlab.com" - let to_string { user; repo; kind } = - sprintf "git+https://%s/%s/%s.git" (host_of_kind kind) user repo - let homepage { kind; user; repo } = let host = host_of_kind kind in sprintf "https://%s/%s/%s" host user repo @@ -292,8 +290,11 @@ module Source_kind = struct | Some v -> Dune_lang.Syntax.since Stanza.syntax v ) >>> plain_string of_string in - let constr = List.assoc kind_string_map kind |> Option.value_exn in + let constr = to_string kind in (constr, decode)) + + let to_string { user; repo; kind } = + sprintf "git+https://%s/%s/%s.git" (host_of_kind kind) user repo end type t =