package opam_bin_lib

  1. Overview
  2. Docs

Source file commandShare.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(**************************************************************************)
(*                                                                        *)
(*    Copyright 2020 OCamlPro & Origin Labs                               *)
(*                                                                        *)
(*  All rights reserved. This file is distributed under the terms of the  *)
(*  GNU Lesser General Public License version 2.1, with the special       *)
(*  exception on linking described in the file LICENSE.                   *)
(*                                                                        *)
(**************************************************************************)

open Ezcmd.TYPES
open Ez_file.V1
open EzFile.OP

let cmd_name = "share"

let cmd =
  let args = ref [] in
  let recursive = ref false in
  let share_dir = ref None in
  Arg.{
    cmd_name ;
    cmd_action = (fun () ->
        let args =
          if !recursive then
            let files = ref [] in
            let rec iter file =
              match Unix.lstat file with
              | exception _ -> ()
              | st ->
                match st.st_kind with
                | Unix.S_REG -> files := file :: !files
                | S_DIR ->
                  begin
                    (* Since opam-bin share will be used on .opam and switches,
                       we should hardcore some directory exclusion... *)
                    match Filename.basename file with
                    | ".opam-switch"
                    | "repo"
                    | "plugins"
                    | "download-cache"
                    | "log"
                    | "var" -> ()
                    | _ ->
                      EzFile.iter_dir ~f:(fun path ->
                          iter ( file // path )
                        ) file
                  end
                | _ -> ()
            in
            List.iter iter ( List.rev !args );
            !files
          else !args
        in
        let share_dir = !share_dir in
        Share.files ?share_dir args) ;
    cmd_args = [
      [ "r" ; "rec" ], Arg.Set recursive,
      Ezcmd.info "Iter on directories";

      [ "share-dir" ], Arg.String (fun dir -> share_dir := Some dir),
      Ezcmd.info "Global directory of shared files" ;

      [], Anons (fun list -> args := list),
      Ezcmd.info "args"
    ];
    cmd_man = [];
    cmd_doc = "Share the following files";
  }
OCaml

Innovation. Community. Security.