aboutsummaryrefslogtreecommitdiff
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
parent14f56876f64e7557ef695633b31e9a1c093f9c3e (diff)
Add support for specifying multiple packages in pkg-status|status
-rw-r--r--bpkg/pkg-status.cli18
-rw-r--r--bpkg/pkg-status.cxx158
2 files changed, 98 insertions, 78 deletions
diff --git a/bpkg/pkg-status.cli b/bpkg/pkg-status.cli
index 87ff442..81403bb 100644
--- a/bpkg/pkg-status.cli
+++ b/bpkg/pkg-status.cli
@@ -15,16 +15,17 @@ namespace bpkg
"\h|SYNOPSIS|
- \c{\b{bpkg pkg-status}|\b{status} [<options>] <pkg>[/<ver>]}
+ \c{\b{bpkg pkg-status}|\b{status} [<options>] <pkg>[/<ver>]...}
\h|DESCRIPTION|
- The \cb{pkg-status} command prints the status of the specified package or,
- if <ver> is specified, package version. Note that the status is written
- to \cb{STDOUT}, not \cb{STDERR}.
+ The \cb{pkg-status} command prints the status of the specified packages
+ or, if <ver> is specified, package versions. Note that the status is
+ written to \cb{STDOUT}, not \cb{STDERR}.
- The status output format is regular. First always comes one of the
- following status words:
+ The status output format is regular. If several packages were specified,
+ then each line starts with the package name (and version, if specified)
+ followed by '\cb{:}'. Then comes one of the following status words:
\dl|
@@ -55,7 +56,6 @@ namespace bpkg
package is part of the configuration and is broken (broken packages
can only be purged; see \l{bpkg-pkg-purge(1)})||
-
If only the package name was specified without the package version, then
the \cb{available} status word is followed by the list of available
versions.
@@ -90,6 +90,10 @@ namespace bpkg
bpkg status libfoo
configured 1.0.0 hold_package; available 1.1.0 1.1.1
+
+ bpkg status libfoo/1.0.0 libbar
+ libfoo/1.0.0: configured hold_package
+ libbar: unknown
\
Assuming now that we dropped \cb{libfoo} from the configuration:
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;
}
}