|
1 | | -(* Walks the directory tree rooted at the current directory, |
2 | | - displaying all directory names (skipping hidden directories and `_build`). *) |
3 | | - |
4 | | -open Eio.Std |
| 1 | +(* Walk the directory tree rooted at the current directory, |
| 2 | + showing a summary for any .mli files. *) |
5 | 3 |
|
6 | 4 | let ( / ) = Eio.Path.( / ) |
7 | 5 |
|
8 | | -let rec scan t = |
| 6 | +let is_doc_comment = String.starts_with ~prefix:"(** " |
| 7 | + |
| 8 | +(* Print the first line of [t]'s doc-comment, if any *) |
| 9 | +let scan_mli t f = |
| 10 | + Eio.Path.with_lines t (fun lines -> |
| 11 | + Seq.find is_doc_comment lines |
| 12 | + |> Option.iter (fun line -> |
| 13 | + let stop = String.index_from_opt line 4 '*' |> Option.value ~default:(String.length line) in |
| 14 | + Format.fprintf f "%a: %s@." Eio.Path.pp t (String.sub line 4 (stop - 4)) |
| 15 | + ) |
| 16 | + ) |
| 17 | + |
| 18 | +(* Walk the tree rooted at [t] and scan any .mli files found. *) |
| 19 | +let rec scan t f = |
9 | 20 | match Eio.Path.kind ~follow:false t with |
10 | 21 | | `Directory -> |
11 | | - traceln "Visiting %a" Eio.Path.pp t; |
12 | 22 | Eio.Path.read_dir t |> List.iter (function |
13 | | - | "_build" -> () |
14 | | - | item when String.starts_with ~prefix:"." item -> () |
15 | | - | item -> scan (t / item) |
16 | | - ) |
| 23 | + | "_build" | "_opam" -> () (* Don't examine these directories *) |
| 24 | + | item when String.starts_with ~prefix:"." item -> () (* Skip hidden items *) |
| 25 | + | item -> scan (t / item) f |
| 26 | + ) |
| 27 | + | `Regular_file when Filename.check_suffix (snd t) ".mli" -> scan_mli t f |
17 | 28 | | _ -> () |
18 | 29 |
|
19 | 30 | let () = |
20 | 31 | Eio_main.run @@ fun env -> |
21 | | - scan (Eio.Stdenv.cwd env) |
| 32 | + scan (Eio.Stdenv.cwd env) Format.std_formatter |
0 commit comments