aboutsummaryrefslogtreecommitdiff
path: root/bpkg/cfg-info.cxx
blob: da49d629521d9896ad79de25d539fe6bde927236 (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
60
// file      : bpkg/cfg-info.cxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#include <bpkg/cfg-info.hxx>

#include <iostream> // cout

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

using namespace std;

namespace bpkg
{
  int
  cfg_info (const cfg_info_options& o, cli::scanner&)
  {
    tracer trace ("cfg_info");

    dir_path c (o.directory ());
    l4 ([&]{trace << "configuration: " << c;});

    database db (c, trace, o.link ());

    try
    {
      cout.exceptions (ostream::badbit | ostream::failbit);

      auto print = [] (const database& db)
      {
        cout << "path: " << db.config                 << endl
             << "uuid: " << db.uuid                   << endl
             << "type: " << db.type                   << endl
             << "name: " << (db.name ? *db.name : "") << endl;
      };

      print (db);

      // Note that there will be no explicit links loaded, unless the --link
      // option is specified.
      //
      for (const linked_config& lc: db.explicit_links ())
      {
        // Skip the self-link.
        //
        if (lc.id != 0)
        {
          cout << endl;
          print (lc.db);
        }
      }
    }
    catch (const io_error&)
    {
      fail << "unable to write to stdout";
    }

    return 0;
  }
}