aboutsummaryrefslogtreecommitdiff
path: root/bdep/fetch.cxx
blob: 6231d8b6ef605b6940610c7add02aba16c337dee (plain)
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
// file      : bdep/fetch.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <bdep/fetch.hxx>

#include <bdep/database.hxx>
#include <bdep/diagnostics.hxx>

using namespace std;

namespace bdep
{
  int
  cmd_fetch (const cmd_fetch_options& o, cli::scanner&)
  {
    tracer trace ("fetch");

    dir_path prj (
      find_project_packages (o, true /* ignore_packages */).project);

    database db (open (prj, trace));

    transaction t (db.begin ());
    configurations cfgs (find_configurations (prj, t, o));
    t.commit ();

    bool first (true);
    for (const shared_ptr<configuration>& c: cfgs)
    {
      if (c->packages.empty ())
      {
        info << "no packages initialized in configuration " << *c;
        continue;
      }

      // If we are fetching in multiple configurations, separate them with a
      // blank line and print the configuration name/directory.
      //
      if (verb && cfgs.size () > 1)
      {
        text << (first ? "" : "\n")
             << "fetching in configuration " << *c;

        first = false;
      }

      // Let's use the repository name rather than the location as a sanity
      // check (the repository must have been added as part of init).
      //
      run_bpkg (o,
                "fetch",
                "-d", c->path,
                (o.full () ? nullptr : ("dir:" + prj.string ()).c_str ()));
    }

    return 0;
  }
}