From ac6df7a77682bf33b486d451c67ed9650bd9bc2f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 16 Sep 2015 16:12:31 +0200 Subject: Implement pkg-status, pkg-purge commands; start ad-hoc test --- bpkg/pkg-status.cxx | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 bpkg/pkg-status.cxx (limited to 'bpkg/pkg-status.cxx') diff --git a/bpkg/pkg-status.cxx b/bpkg/pkg-status.cxx new file mode 100644 index 0000000..0d8c474 --- /dev/null +++ b/bpkg/pkg-status.cxx @@ -0,0 +1,85 @@ +// file : bpkg/pkg-status.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include // cout + +#include +#include +#include +#include +#include +#include + +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; + 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 p (db.query_one (q)); + + 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; + } +} -- cgit v1.1