blob: 26267b6354b51a1135273fad74ba5e22761a417c (
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// file : bpkg/pkg-status.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
#include <bpkg/pkg-status>
#include <iostream> // cout
#include <bpkg/types>
#include <bpkg/package>
#include <bpkg/package-odb>
#include <bpkg/utility>
#include <bpkg/database>
#include <bpkg/diagnostics>
using namespace std;
using namespace butl;
namespace bpkg
{
void
pkg_status (const pkg_status_options& o, cli::scanner& args)
{
tracer trace ("pkg_status");
dir_path c (o.directory ());
level4 ([&]{trace << "configuration: " << c;});
if (!args.more ())
fail << "package name argument expected" <<
info << "run 'bpkg help pkg-status' for more information";
string n (args.next ());
version v;
if (args.more ())
{
const char* s (args.next ());
try
{
v = version (s);
}
catch (const invalid_argument& e)
{
fail << "invalid package version '" << s << "'";
}
}
database db (open (c));
transaction t (db.begin ());
using query = odb::query<package>;
query q (query::name == n);
if (!v.empty ())
{
q = q && (query::version.epoch == v.epoch () &&
query::version.revision == v.revision () &&
query::version.canonical_upstream == v.canonical_upstream ());
}
shared_ptr<package> p (db.query_one<package> (q));
t.commit ();
if (p == nullptr)
{
// @@ TODO: This is where we search the packages available in
// the repositories and if found, print its status as 'available'
// plus a list of versions.
//
cout << "unknown";
}
else
{
cout << p->state;
// Also print the version of the package unless the user
// specified it.
//
if (v.empty ())
cout << " " << p->version;
}
cout << endl;
}
}
|