From 0143c3ff25a753df6f73d6319f7fb4a62a4d53c6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 25 Sep 2015 07:12:49 +0200 Subject: Implement rep-info command --- bpkg/rep-info.cxx | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 bpkg/rep-info.cxx (limited to 'bpkg/rep-info.cxx') diff --git a/bpkg/rep-info.cxx b/bpkg/rep-info.cxx new file mode 100644 index 0000000..64ac9b1 --- /dev/null +++ b/bpkg/rep-info.cxx @@ -0,0 +1,117 @@ +// file : bpkg/rep-info.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include // cout +#include // invalid_argument + +#include +#include + +#include +#include +#include +#include + +using namespace std; +using namespace butl; + +namespace bpkg +{ + void + rep_info (const rep_info_options& o, cli::scanner& args) + { + tracer trace ("rep_info"); + + if (!args.more ()) + fail << "repository location argument expected" << + info << "run 'bpkg help rep-info' for more information"; + + // Figure out the repository location. + // + // @@ The same code as in rep-add, factor out. + // + const char* arg (args.next ()); + repository_location rl; + try + { + rl = repository_location (arg, repository_location ()); + + if (rl.relative ()) // Throws if location is empty. + rl = repository_location ( + dir_path (arg).complete ().normalize ().string ()); + } + catch (const invalid_argument& e) + { + fail << "invalid repository location '" << arg << "': " << e.what (); + } + + // Fetch everything we will need before printing anything. + // + repository_manifests rms (fetch_repositories (o, rl)); + package_manifests pms (fetch_packages (o, rl)); + + // Now print. + // + bool all (!o.name () && !o.repositories () && !o.packages ()); + + try + { + cout.exceptions (ostream::badbit | ostream::failbit); + + if (all || o.name ()) + cout << rl.canonical_name () << " " << rl << endl; + + // Repositories. + // + if (all || o.repositories ()) + { + if (o.manifest ()) + { + manifest_serializer s (cout, "STDOUT"); + rms.serialize (s); + } + else + { + for (const repository_manifest& rm: rms) + { + if (rm.location.empty ()) + continue; // Itself. + + repository_location l (rm.location, rl); // Complete. + + //@@ Handle complements. + // + cout << "prerequisite " << l.canonical_name () << " " << l << endl; + } + } + } + + // Packages. + // + if (all || o.packages ()) + { + if (o.manifest ()) + { + manifest_serializer s (cout, "STDOUT"); + pms.serialize (s); + } + else + { + for (const package_manifest& pm: pms) + cout << pm.name << " " << pm.version << endl; + } + } + } + catch (const manifest_serialization& e) + { + fail << "unable to serialize manifest: " << e.description; + } + catch (const ostream::failure&) + { + fail << "unable to write to STDOUT"; + } + } +} -- cgit v1.1