From 5487be65a6f493968c0e997d93bcd5c2d87158ef Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 14 Mar 2018 11:55:38 +0200 Subject: Add --no-result option to suppress printing informational messages --- bpkg/cfg-create.cxx | 2 +- bpkg/common.cli | 9 +++++++++ bpkg/fetch-git.cxx | 9 ++++++--- bpkg/pkg-build.cxx | 18 +++++++++--------- bpkg/pkg-checkout.cxx | 2 +- bpkg/pkg-command.cxx | 2 +- bpkg/pkg-configure.cxx | 2 +- bpkg/pkg-disfigure.cxx | 2 +- bpkg/pkg-drop.cxx | 4 ++-- bpkg/pkg-fetch.cxx | 2 +- bpkg/pkg-purge.cxx | 4 ++-- bpkg/pkg-unpack.cxx | 2 +- bpkg/pkg-verify.cxx | 2 +- bpkg/rep-add.cxx | 8 +++++--- bpkg/rep-add.hxx | 2 +- bpkg/rep-create.cxx | 6 +++--- bpkg/rep-fetch.cxx | 8 ++++---- bpkg/rep-remove.cxx | 9 +++++---- bpkg/rep-remove.hxx | 5 ++++- 19 files changed, 58 insertions(+), 40 deletions(-) (limited to 'bpkg') diff --git a/bpkg/cfg-create.cxx b/bpkg/cfg-create.cxx index 70d8848..8fd3a05 100644 --- a/bpkg/cfg-create.cxx +++ b/bpkg/cfg-create.cxx @@ -102,7 +102,7 @@ namespace bpkg db.persist (repository (repository_location ())); t.commit (); - if (verb) + if (verb && !o.no_result ()) { c.complete ().normalize (); text << "created new configuration in " << c; diff --git a/bpkg/common.cli b/bpkg/common.cli index 5c3de83..89bebb5 100644 --- a/bpkg/common.cli +++ b/bpkg/common.cli @@ -81,6 +81,15 @@ namespace bpkg \li|Even more detailed information.||" } + // In the future we may also have --structured-result, similar to the + // build system. + // + bool --no-result + { + "Don't print informational messages about the outcome of performing + a command." + } + path --build { "", diff --git a/bpkg/fetch-git.cxx b/bpkg/fetch-git.cxx index 17c56c5..833c3a7 100644 --- a/bpkg/fetch-git.cxx +++ b/bpkg/fetch-git.cxx @@ -665,8 +665,11 @@ namespace bpkg // This makes it hard to understand which superproject/submodule is // currently being fetched. Let's fix that. // + // Note that we have "fixed" that capital letter nonsense (hoping that + // git-clone will do the same at some point). + // if (verb != 0) - text << "Fetching in '" << dir.posix_string () << "'..."; + text << "fetching in '" << dir.posix_string () << "'..."; // Note that we suppress the (too detailed) fetch command output if the // verbosity level is 1. However, we still want to see the progress in @@ -878,10 +881,10 @@ namespace bpkg update_tree (co, fsdir, psdir, ref, cap, shallow, to); // Not quite a checkout, but let's make the message match the - // git-submodule script output. + // git-submodule script output (again, except for capitalization). // if (verb > 0) - text << "Submodule path '" << psd << "': checked out '" << commit + text << "submodule path '" << psd << "': checked out '" << commit << "'"; // Recurse. diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx index 28105d4..5b91ec3 100644 --- a/bpkg/pkg-build.cxx +++ b/bpkg/pkg-build.cxx @@ -1964,7 +1964,7 @@ namespace bpkg assert (sp->state == package_state::unpacked || sp->state == package_state::transient); - if (verb) + if (verb && !o.no_result ()) text << (sp->state == package_state::transient ? "purged " : "disfigured ") << *sp; @@ -2011,7 +2011,7 @@ namespace bpkg transaction t (db.begin ()); pkg_purge (c, t, sp); // Commits the transaction. - if (verb) + if (verb && !o.no_result ()) text << "purged " << *sp; if (!p.hold_package) @@ -2117,7 +2117,7 @@ namespace bpkg assert (sp->state == package_state::fetched || sp->state == package_state::unpacked); - if (verb) + if (verb && !o.no_result ()) { const repository_location& rl (sp->repository); @@ -2163,7 +2163,7 @@ namespace bpkg transaction t (db.begin ()); sp = pkg_unpack (o, c, t, ap->id.name); // Commits the transaction. - if (verb) + if (verb && !o.no_result ()) text << "unpacked " << *sp; } else @@ -2179,7 +2179,7 @@ namespace bpkg true, // Replace. false); // Don't purge; commits the transaction. - if (verb) + if (verb && !o.no_result ()) text << "using " << *sp << " (external)"; } @@ -2213,7 +2213,7 @@ namespace bpkg assert (sp->state == package_state::configured); - if (verb) + if (verb && !o.no_result ()) text << "configured " << *sp; } @@ -2254,10 +2254,10 @@ namespace bpkg if (verb > 1) { if (hp) - text << "hold package " << sp->name; + text << "holding package " << sp->name; if (hv) - text << "hold version " << *sp; + text << "holding version " << *sp; } } } @@ -2312,7 +2312,7 @@ namespace bpkg pkg_update (c, o, o.for_ (), strings (), upkgs); - if (verb) + if (verb && !o.no_result ()) { for (const pkg_command_vars& pv: upkgs) text << "updated " << *pv.pkg; diff --git a/bpkg/pkg-checkout.cxx b/bpkg/pkg-checkout.cxx index f068b54..14f84cb 100644 --- a/bpkg/pkg-checkout.cxx +++ b/bpkg/pkg-checkout.cxx @@ -236,7 +236,7 @@ namespace bpkg // p = pkg_checkout (o, c, t, move (n), move (v), o.replace ()); - if (verb) + if (verb && !o.no_result ()) text << "checked out " << *p; return 0; diff --git a/bpkg/pkg-command.cxx b/bpkg/pkg-command.cxx index 0f54b95..f287886 100644 --- a/bpkg/pkg-command.cxx +++ b/bpkg/pkg-command.cxx @@ -154,7 +154,7 @@ namespace bpkg pkg_command (cmd, c, o, cmd_v, cvars, ps); - if (verb) + if (verb && !o.no_result ()) { for (const pkg_command_vars& pv: ps) text << cmd << (cmd.back () != 'e' ? "ed " : "d ") << *pv.pkg; diff --git a/bpkg/pkg-configure.cxx b/bpkg/pkg-configure.cxx index 19b64d9..2bb1b20 100644 --- a/bpkg/pkg-configure.cxx +++ b/bpkg/pkg-configure.cxx @@ -301,7 +301,7 @@ namespace bpkg pkg_configure (c, o, t, p, vars); } - if (verb) + if (verb && !o.no_result ()) text << "configured " << *p; return 0; diff --git a/bpkg/pkg-disfigure.cxx b/bpkg/pkg-disfigure.cxx index 9153a6a..4dcecaa 100644 --- a/bpkg/pkg-disfigure.cxx +++ b/bpkg/pkg-disfigure.cxx @@ -188,7 +188,7 @@ namespace bpkg assert (p->state == package_state::unpacked || p->state == package_state::transient); - if (verb) + if (verb && !o.no_result ()) text << (p->state == package_state::transient ? "purged " : "disfigured ") << *p; diff --git a/bpkg/pkg-drop.cxx b/bpkg/pkg-drop.cxx index 6e28c37..a238803 100644 --- a/bpkg/pkg-drop.cxx +++ b/bpkg/pkg-drop.cxx @@ -362,7 +362,7 @@ namespace bpkg assert (p->state == package_state::unpacked || p->state == package_state::transient); - if (verb) + if (verb && !o.no_result ()) text << (p->state == package_state::transient ? "purged " : "disfigured ") << p->name; @@ -391,7 +391,7 @@ namespace bpkg transaction t (db.begin ()); pkg_purge (c, t, p); // Commits the transaction, p is now transient. - if (verb) + if (verb && !o.no_result ()) text << "purged " << p->name; } diff --git a/bpkg/pkg-fetch.cxx b/bpkg/pkg-fetch.cxx index ff04411..664c92f 100644 --- a/bpkg/pkg-fetch.cxx +++ b/bpkg/pkg-fetch.cxx @@ -296,7 +296,7 @@ namespace bpkg p = pkg_fetch (o, c, t, move (n), move (v), o.replace ()); } - if (verb) + if (verb && !o.no_result ()) { if (!o.existing ()) text << "fetched " << *p; diff --git a/bpkg/pkg-purge.cxx b/bpkg/pkg-purge.cxx index 7b58461..fa5ce01 100644 --- a/bpkg/pkg-purge.cxx +++ b/bpkg/pkg-purge.cxx @@ -202,8 +202,8 @@ namespace bpkg p->state = package_state::transient; } - if (verb) - text << (o.keep () ? "keeping archive " : "purged ") << *p; + if (verb && !o.no_result ()) + text << (o.keep () ? "keeping archive " : "purged ") << *p; return 0; } diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx index 7472194..d9d54ea 100644 --- a/bpkg/pkg-unpack.cxx +++ b/bpkg/pkg-unpack.cxx @@ -447,7 +447,7 @@ namespace bpkg : pkg_unpack (c, t, move (n), move (v), o.replace ()); } - if (verb) + if (verb && !o.no_result ()) { if (!external) text << "unpacked " << *p; diff --git a/bpkg/pkg-verify.cxx b/bpkg/pkg-verify.cxx index ee3cfe4..bb2f3b8 100644 --- a/bpkg/pkg-verify.cxx +++ b/bpkg/pkg-verify.cxx @@ -188,7 +188,7 @@ namespace bpkg package_manifest m ( pkg_verify (o, a, o.ignore_unknown (), !o.silent ())); - if (verb && !o.silent ()) + if (verb && !o.silent () && !o.no_result ()) text << "valid package " << m.name << " " << m.version; return 0; diff --git a/bpkg/rep-add.cxx b/bpkg/rep-add.cxx index 6db2c92..704da68 100644 --- a/bpkg/rep-add.cxx +++ b/bpkg/rep-add.cxx @@ -16,7 +16,9 @@ using namespace butl; namespace bpkg { shared_ptr - rep_add (transaction& t, const repository_location& rl) + rep_add (const common_options& o, + transaction& t, + const repository_location& rl) { const string& rn (rl.canonical_name ()); @@ -46,7 +48,7 @@ namespace bpkg if (added) db.update (root); - if (verb) + if (verb && !o.no_result ()) text << (added ? "added " : updated ? "updated " : "unchanged ") << rn; return r; @@ -76,7 +78,7 @@ namespace bpkg ? optional (o.type ()) : nullopt)); - rep_add (t, rl); + rep_add (o, t, rl); } t.commit (); diff --git a/bpkg/rep-add.hxx b/bpkg/rep-add.hxx index 226f0e2..484d6a8 100644 --- a/bpkg/rep-add.hxx +++ b/bpkg/rep-add.hxx @@ -23,7 +23,7 @@ namespace bpkg // repository if it is not already. // shared_ptr - rep_add (transaction&, const repository_location&); + rep_add (const common_options&, transaction&, const repository_location&); } #endif // BPKG_REP_ADD_HXX diff --git a/bpkg/rep-create.cxx b/bpkg/rep-create.cxx index 56f2f87..ba2eb73 100644 --- a/bpkg/rep-create.cxx +++ b/bpkg/rep-create.cxx @@ -202,8 +202,8 @@ namespace bpkg { package_manifest& m (p.second.manifest); - if (verb) - text << "adding " << m.name << " " << m.version; + if (verb && !o.no_result ()) + text << "added " << m.name << " " << m.version; manifests.emplace_back (move (m)); } @@ -267,7 +267,7 @@ namespace bpkg fail << "unable to write to " << p << ": " << e; } - if (verb) + if (verb && !o.no_result ()) { d.complete (); d.normalize (); diff --git a/bpkg/rep-fetch.cxx b/bpkg/rep-fetch.cxx index b443118..00454f9 100644 --- a/bpkg/rep-fetch.cxx +++ b/bpkg/rep-fetch.cxx @@ -794,7 +794,7 @@ namespace bpkg warn << "repository state is now broken and will be cleaned up" << info << "run 'bpkg rep-fetch' to update"; - rep_remove_clean (conf, t.database ()); + rep_remove_clean (o, conf, t.database ()); } throw; @@ -827,7 +827,7 @@ namespace bpkg // same location. // if (ua.find (r) == ua.end () || r.load ()->location.url () != rl.url ()) - rep_add (t, rl); + rep_add (o, t, rl); repos.emplace_back (r); } @@ -903,7 +903,7 @@ namespace bpkg // auto i (ua.find (r)); if (i == ua.end () || i->load ()->location.url () != rl.url ()) - r = lazy_shared_ptr (db, rep_add (t, rl)); + r = lazy_shared_ptr (db, rep_add (o, t, rl)); } repos.emplace_back (move (r)); @@ -927,7 +927,7 @@ namespace bpkg t.commit (); - if (verb) + if (verb && !o.no_result ()) text << pcount << " package(s) in " << rcount << " repository(s)"; return 0; diff --git a/bpkg/rep-remove.cxx b/bpkg/rep-remove.cxx index eadb63f..53a7de1 100644 --- a/bpkg/rep-remove.cxx +++ b/bpkg/rep-remove.cxx @@ -182,7 +182,8 @@ namespace bpkg } void - rep_remove_clean (const dir_path& c, + rep_remove_clean (const common_options& o, + const dir_path& c, database& db, bool quiet) { @@ -216,7 +217,7 @@ namespace bpkg r->prerequisites.clear (); db.update (r); - if (verb >= (quiet ? 2 : 1)) + if (verb >= (quiet ? 2 : 1) && !o.no_result ()) text << "cleaned " << r->name; } else @@ -285,7 +286,7 @@ namespace bpkg // if (o.clean ()) { - rep_remove_clean (c, db, false /* quiet */); + rep_remove_clean (o, c, db, false /* quiet */); return 0; } @@ -383,7 +384,7 @@ namespace bpkg { rep_remove (c, t, r.load ()); - if (verb) + if (verb && !o.no_result ()) text << "removed " << r.object_id (); } diff --git a/bpkg/rep-remove.hxx b/bpkg/rep-remove.hxx index a8d4908..68d8a36 100644 --- a/bpkg/rep-remove.hxx +++ b/bpkg/rep-remove.hxx @@ -40,7 +40,10 @@ namespace bpkg // - Remove all available packages. // void - rep_remove_clean (const dir_path& conf, database&, bool quiet = true); + rep_remove_clean (const common_options&, + const dir_path& conf, + database&, + bool quiet = true); // Remove a repository from locations of the available packages it // contains. Remove packages that come from only this repository. -- cgit v1.1