forked from
gazagnaire.org/irmin
Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
1(** List command. *)
2
3let run ~repo ~branch ~output prefix =
4 let config = Config.load ~repo () in
5 let (module B : Common.BACKEND) = Common.backend_of_config config in
6 Eio_main.run @@ fun env ->
7 let fs = Eio.Stdenv.cwd env in
8 Eio.Switch.run @@ fun sw ->
9 let store = B.open_store ~sw ~fs ~config in
10 match B.checkout store ~branch with
11 | None ->
12 Common.error "Branch %a not found" Common.styled_cyan branch;
13 1
14 | Some tree ->
15 let path =
16 match prefix with None -> [] | Some p -> Common.path_of_string p
17 in
18 let entries = B.tree_list tree path in
19 (match output with
20 | `Human ->
21 List.iter
22 (fun (name, kind) ->
23 let suffix = match kind with `Node -> "/" | `Contents -> "" in
24 Fmt.pr "%s%s@." name suffix)
25 entries
26 | `Json ->
27 let json_entries =
28 List.map
29 (fun (name, kind) ->
30 let k =
31 match kind with `Node -> "dir" | `Contents -> "file"
32 in
33 Printf.sprintf {|{"name":%S,"type":%S}|} name k)
34 entries
35 in
36 Fmt.pr "[%s]@." (String.concat "," json_entries));
37 0