package drom_lib

  1. Overview
  2. Docs

Source file commandUpdate.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
(**************************************************************************)
(*                                                                        *)
(*    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.V2

let cmd_name = "update"

let action ~args () =
  let (p : Types.project) =
    Build.build ~force_build_deps:false ~build_deps:true ~build:false ~args ()
  in
  let y = args.arg_yes in

  Opam.run ~y [ "update" ] [];
  Opam.run ~y:true [ "pin" ] [ "-k"; "path"; "--no-action"; "./_drom" ];
  let deps_package = p.package.name ^ "-deps" in
  Opam.run ~y [ "install" ] [ deps_package ];
  let error = ref None in
  Opam.run ~y ~error [ "upgrade" ] [];
  Opam.run ~error [ "unpin" ] [ "-y"; deps_package ];
  match !error with
  | None -> Printf.eprintf "Switch Update OK\n%!"
  | Some exn -> raise exn

let cmd =
  let args, specs = Build.build_args () in
  EZCMD.sub cmd_name
    (fun () -> action ~args ())
    ~args: specs
    ~doc: "Update packages in switch"
    ~man: [
      `S "DESCRIPTION";
      `Blocks [
        `P "This command performs the following actions:";
        `I ( "1.", "Call $(b,opam update) to get information on newly available packages");
        `I ( "2.", "Pin the package dependencies in the local opam switch");
        `I ( "3.", "Call $(b,opam upgrade) to upgrade packages in the local opam switch");
        `I ( "4.", "Unpin package dependencies");
      ]
    ]