@@ -163,8 +163,59 @@ let print_element elt =
163163 | Element. ClassType v -> print_json_desc Lang_desc. classtype_t v
164164 | Element. Class v -> print_json_desc Lang_desc. class_t v
165165
166- let run inp ref =
166+ let print_short c elt =
167+ let open Odoc_xref2 in
168+ let open Component.Fmt in
169+ match elt with
170+ | Element. Module m ->
171+ let m' = Component.Of_Lang. (module_ (empty () ) m) in
172+ Format. fprintf Format. std_formatter " @[<v 2>module %a %a@]"
173+ (model_identifier c)
174+ (m.id :> Odoc_model.Paths.Identifier.t )
175+ (module_ c) m'
176+ | Element. ModuleType m ->
177+ let m' = Component.Of_Lang. (module_type (empty () ) m) in
178+ Format. fprintf Format. std_formatter " @[<v 2>module type %a %a@]"
179+ (model_identifier c)
180+ (m.id :> Odoc_model.Paths.Identifier.t )
181+ (module_type c) m'
182+ | Element. Type t ->
183+ let t' = Component.Of_Lang. (type_decl (empty () ) t) in
184+ Format. fprintf Format. std_formatter " @[<v 2>type %a %a@]"
185+ (model_identifier c)
186+ (t.id :> Odoc_model.Paths.Identifier.t )
187+ (type_decl c) t'
188+ | Element. Value v ->
189+ let v' = Component.Of_Lang. (value (empty () ) v) in
190+ Format. fprintf Format. std_formatter " @[<v 2>val %a %a@]"
191+ (model_identifier c)
192+ (v.id :> Odoc_model.Paths.Identifier.t )
193+ (value c) v'
194+ | Element. ClassType ct ->
195+ let ct' = Component.Of_Lang. (class_type (empty () ) ct) in
196+ Format. fprintf Format. std_formatter " @[<v 2>val %a %a@]"
197+ (model_identifier c)
198+ (ct.id :> Odoc_model.Paths.Identifier.t )
199+ (class_type c) ct'
200+ | Element. Class cls ->
201+ let cls' = Component.Of_Lang. (class_ (empty () ) cls) in
202+ Format. fprintf Format. std_formatter " @[<v 2>val %a %a@]"
203+ (model_identifier c)
204+ (cls.id :> Odoc_model.Paths.Identifier.t )
205+ (class_ c) cls'
206+
207+ let run inp short long_paths show_canonical show_expansions
208+ show_include_expansions show_removed ref =
167209 let inp = Fpath. v inp in
210+ let c =
211+ {
212+ Odoc_xref2.Component.Fmt. short_paths = not long_paths;
213+ show_canonical;
214+ show_expansions;
215+ show_include_expansions;
216+ show_removed;
217+ }
218+ in
168219 Odoc_file. load inp >> = fun unit ->
169220 match unit .content with
170221 | Odoc_file. Source_tree_content tree ->
@@ -177,25 +228,26 @@ let run inp ref =
177228 print_json_desc Lang_desc. implementation_t impl;
178229 Ok ()
179230 | Unit_content u -> (
180- match ref with
181- | None ->
182- print_json_desc Lang_desc. compilation_unit_t u;
231+ match (short, ref , u.content) with
232+ | true , None , Module sg ->
233+ let sg' = Odoc_xref2.Component.Of_Lang. (signature (empty () ) sg) in
234+ Format. printf " %a\n %!" Odoc_xref2.Component.Fmt. (signature c) sg';
183235 Ok ()
184- | Some r -> (
236+ | _ , Some r , Module sg -> (
185237 let r = Odoc_model.Semantics. parse_reference r in
186- let sg =
187- match u.content with
188- | Module m -> m
189- | Pack _ -> failwith " Can't look up in packed modules"
190- in
191238 match Odoc_model.Error. raise_warnings r with
192239 | Ok r -> (
193240 match handle_ref sg r with
194241 | Some elt ->
195- print_element elt;
242+ if short then print_short c elt else print_element elt;
196243 Ok ()
197244 | None -> Ok () )
198- | _ -> Ok () ))
245+ | _ -> Ok () )
246+ | true , None , _ -> Error (`Msg " Can't short-print packed modules" )
247+ | _ , Some _ , _ -> Error (`Msg " Can't look up in packed modules" )
248+ | false , None , _ ->
249+ print_json_desc Lang_desc. compilation_unit_t u;
250+ Ok () )
199251
200252open Compatcmdliner
201253
@@ -207,9 +259,37 @@ let a_inp =
207259 let doc = " Input file." in
208260 Arg. (required & pos 0 (some file) None & info ~doc ~docv: " PATH" [] )
209261
262+ let a_short =
263+ let doc = " Short output." in
264+ Arg. (value & flag & info ~doc [ " short" ])
265+
266+ let a_show_expansions =
267+ let doc = " Show expansions in short output" in
268+ Arg. (value & flag & info ~doc [ " show-expansions" ])
269+
270+ let a_long_paths =
271+ let doc = " Show long paths in short output" in
272+ Arg. (value & flag & info ~doc [ " long-paths" ])
273+
274+ let a_show_canonical =
275+ let doc = " Show modules canonical reference in short output" in
276+ Arg. (value & flag & info ~doc [ " show-canonical" ])
277+
278+ let a_show_include_expansions =
279+ let doc = " Show include expansions in short output" in
280+ Arg. (value & flag & info ~doc [ " show-include-expansions" ])
281+
282+ let a_show_removed =
283+ let doc = " Show removed items in signature expansions in short output." in
284+ Arg. (value & flag & info ~doc [ " show-removed" ])
285+
210286let term =
211287 let doc = " Print the content of .odoc files into a text format. For tests" in
212- Term. (const run $ a_inp $ reference, info " odoc_print" ~doc )
288+ Term.
289+ ( const run $ a_inp $ a_short $ a_long_paths $ a_show_canonical
290+ $ a_show_expansions $ a_show_include_expansions $ a_show_removed
291+ $ reference,
292+ info " odoc_print" ~doc )
213293
214294let () =
215295 match Term. eval term with
0 commit comments