aboutsummaryrefslogtreecommitdiff
path: root/bpkg/pkg-status.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-01-26 14:58:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-01-26 14:58:09 +0200
commit733ed5b60710c64a1851ad92706c52fcf58c19f7 (patch)
tree1bf53140ee7b8d1da49fec505c0c688a855d8408 /bpkg/pkg-status.cxx
parent14f56876f64e7557ef695633b31e9a1c093f9c3e (diff)
Add support for specifying multiple packages in pkg-status|status
Diffstat (limited to 'bpkg/pkg-status.cxx')
-rw-r--r--bpkg/pkg-status.cxx158
1 files changed, 87 insertions, 71 deletions
diff --git a/bpkg/pkg-status.cxx b/bpkg/pkg-status.cxx
index 98c583a..896ffe9 100644
--- a/bpkg/pkg-status.cxx
+++ b/bpkg/pkg-status.cxx
@@ -32,106 +32,122 @@ namespace bpkg
fail << "package name argument expected" <<
info << "run 'bpkg help pkg-status' for more information";
- const char* arg (args.next ());
- string n (parse_package_name (arg));
- version v (parse_package_version (arg));
-
- level4 ([&]{trace << "package " << n << "; version " << v;});
-
database db (open (c, trace));
transaction t (db.begin ());
session s;
- // First search in the packages that already exist in this configuration.
- //
- shared_ptr<selected_package> p;
+ for (bool multi (false); args.more (); )
{
- using query = query<selected_package>;
- query q (query::name == n);
+ const char* arg (args.next ());
+ multi = multi || args.more ();
- if (!v.empty ())
- q = q && compare_version_eq (query::version, v, v.revision != 0);
+ string n (parse_package_name (arg));
+ version v (parse_package_version (arg));
- p = db.query_one<selected_package> (q);
- }
+ level4 ([&]{trace << "package " << n << "; version " << v;});
- // Now look for available packages. If the user specified the version
- // explicitly and we found the corresponding existing package, then
- // no need to look for it in available packages.
- //
- vector<shared_ptr<available_package>> aps;
- {
- using query = query<available_package>;
-
- query q (query::id.name == n);
-
- // If we found an existing package, then only look for versions greater
- // than what already exists.
+ // First search in the packages that already exist in this configuration.
//
- if (p != nullptr)
+ shared_ptr<selected_package> p;
{
- q = q && query::id.version > p->version;
- q += order_by_version_desc (query::id.version);
+ using query = query<selected_package>;
+ query q (query::name == n);
+
+ if (!v.empty ())
+ q = q && compare_version_eq (query::version, v, v.revision != 0);
+
+ p = db.query_one<selected_package> (q);
}
+
+ // Now look for available packages. If the user specified the version
+ // explicitly and we found the corresponding existing package, then
+ // no need to look for it in available packages.
//
- // Otherwise, if the user specified the version, then only look for that
- // specific version (we still do it since there are might be other
- // revisions).
- //
- else if (!v.empty ())
+ vector<shared_ptr<available_package>> aps;
{
- q = q && compare_version_eq (query::id.version, v, v.revision != 0);
- q += order_by_revision_desc (query::id.version);
+ using query = query<available_package>;
+
+ query q (query::id.name == n);
+
+ // If we found an existing package, then only look for versions greater
+ // than what already exists.
+ //
+ if (p != nullptr)
+ {
+ q = q && query::id.version > p->version;
+ q += order_by_version_desc (query::id.version);
+ }
+ //
+ // Otherwise, if the user specified the version, then only look for
+ // that specific version (we still do it since there are might be other
+ // revisions).
+ //
+ else if (!v.empty ())
+ {
+ q = q && compare_version_eq (query::id.version, v, v.revision != 0);
+ q += order_by_revision_desc (query::id.version);
+ }
+
+ // Only consider packages that are in repositories that were explicitly
+ // added to the configuration and their complements, recursively.
+ //
+ aps = filter (db.load<repository> (""),
+ db.query<available_package> (q));
}
- // Only consider packages that are in repositories that were explicitly
- // added to the configuration and their complements, recursively.
- //
- aps = filter (db.load<repository> (""), db.query<available_package> (q));
- }
+ if (multi)
+ {
+ cout << n;
- t.commit ();
+ if (!v.empty ())
+ cout << '/' << v;
- bool found (false);
+ cout << ": ";
+ }
- if (p != nullptr)
- {
- cout << p->state;
+ bool found (false);
- // Also print the version of the package unless the user specified it.
- //
- if (v != p->version)
- cout << " " << p->version;
+ if (p != nullptr)
+ {
+ cout << p->state;
- if (p->hold_package)
- cout << " hold_package";
+ // Also print the version of the package unless the user specified it.
+ //
+ if (v != p->version)
+ cout << " " << p->version;
- if (p->hold_version)
- cout << " hold_version";
+ if (p->hold_package)
+ cout << " hold_package";
- found = true;
- }
+ if (p->hold_version)
+ cout << " hold_version";
- if (!aps.empty ())
- {
- cout << (found ? "; " : "") << "available";
+ found = true;
+ }
- // If the user specified the version, then there might only be one
- // entry in which case it is useless to repeat it.
- //
- if (v.empty () || aps.size () > 1 || aps[0]->version != v)
+ if (!aps.empty ())
{
- for (shared_ptr<available_package> ap: aps)
- cout << ' ' << ap->version;
+ cout << (found ? "; " : "") << "available";
+
+ // If the user specified the version, then there might only be one
+ // entry in which case it is useless to repeat it.
+ //
+ if (v.empty () || aps.size () > 1 || aps[0]->version != v)
+ {
+ for (shared_ptr<available_package> ap: aps)
+ cout << ' ' << ap->version;
+ }
+
+ found = true;
}
- found = true;
- }
+ if (!found)
+ cout << "unknown";
- if (!found)
- cout << "unknown";
+ cout << endl;
+ }
- cout << endl;
+ t.commit ();
return 0;
}
}