Skip to content

Commit

Permalink
refactor(describe): remove describe_common lib
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Caglayan <alizter@gmail.com>
  • Loading branch information
Alizter committed Jun 9, 2023
1 parent e48a290 commit c57cf76
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 319 deletions.
174 changes: 0 additions & 174 deletions bin/describe/describe_common.ml

This file was deleted.

133 changes: 0 additions & 133 deletions bin/describe/describe_common.mli

This file was deleted.

4 changes: 2 additions & 2 deletions bin/describe/describe_external_lib_deps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ let to_dyn context_name external_resolved_libs =
let term =
let+ common = Common.term
and+ context_name = Common.context_arg ~doc:"Build context to use."
and+ format = Describe_common.Format.arg in
and+ format = Describe_format.arg in
let config = Common.init common in
Scheduler.go ~common ~config @@ fun () ->
let open Fiber.O in
Expand All @@ -175,7 +175,7 @@ let term =
in
external_resolved_libs setup super_context
>>| to_dyn context_name
>>| Describe_common.Format.print_dyn format
>>| Describe_format.print_dyn format

let command =
let doc =
Expand Down
31 changes: 31 additions & 0 deletions bin/describe/describe_format.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
open Stdune
open Import

type t =
| Sexp
| Csexp

let all = [ ("sexp", Sexp); ("csexp", Csexp) ]

let arg =
let doc = Printf.sprintf "$(docv) must be %s" (Arg.doc_alts_enum all) in
Arg.(value & opt (enum all) Sexp & info [ "format" ] ~docv:"FORMAT" ~doc)

let print_as_sexp dyn =
let rec dune_lang_of_sexp : Sexp.t -> Dune_lang.t = function
| Atom s -> Dune_lang.atom_or_quoted_string s
| List l -> List (List.map l ~f:dune_lang_of_sexp)
in
let cst =
dyn |> Sexp.of_dyn |> dune_lang_of_sexp
|> Dune_lang.Ast.add_loc ~loc:Loc.none
|> Dune_lang.Cst.concrete
in
let version = Dune_lang.Syntax.greatest_supported_version Stanza.syntax in
Pp.to_fmt Stdlib.Format.std_formatter
(Dune_lang.Format.pp_top_sexps ~version [ cst ])

let print_dyn t dyn =
match t with
| Csexp -> Csexp.to_channel stdout (Sexp.of_dyn dyn)
| Sexp -> print_as_sexp dyn
11 changes: 11 additions & 0 deletions bin/describe/describe_format.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
open Import

(** Formatting utilities for dune describe commands *)

type t =
| Sexp
| Csexp

val arg : t Term.t

val print_dyn : t -> Dyn.t -> unit
4 changes: 2 additions & 2 deletions bin/describe/describe_opam_files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Stdune

let term =
let+ common = Common.term
and+ format = Describe_common.Format.arg in
and+ format = Describe_format.arg in
let config = Common.init common in
Scheduler.go ~common ~config @@ fun () ->
Build_system.run_exn @@ fun () ->
Expand All @@ -26,7 +26,7 @@ let term =
Dyn.Tuple [ String (Path.to_string opam_file); String contents ]
in
Dyn.List (List.map packages ~f:opam_file_to_dyn)
|> Describe_common.Format.print_dyn format
|> Describe_format.print_dyn format

let command =
let doc =
Expand Down
Loading

0 comments on commit c57cf76

Please sign in to comment.