diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2016-09-15 15:01:48 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2016-09-16 13:03:06 +0300 |
commit | 564801acd608513adb07244829735ffb2669685d (patch) | |
tree | 9a28b539c5cd39954868452d2991f83e0db49b3f | |
parent | 11aea04f6499b5cdade754c89bc435d851c23679 (diff) |
Don't prompt if build/drop plan is obvious
-rw-r--r-- | bpkg/pkg-build.cxx | 34 | ||||
-rw-r--r-- | bpkg/pkg-drop.cxx | 24 |
2 files changed, 49 insertions, 9 deletions
diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx index a6d51c9..79fc90c 100644 --- a/bpkg/pkg-build.cxx +++ b/bpkg/pkg-build.cxx @@ -1455,6 +1455,14 @@ namespace bpkg // bool update_dependents (false); + // Print the plan and ask for the user's confirmation only if some implicit + // action (such as building prerequisite or reconfiguring dependent + // package) to be taken or there is a selected package which version must + // be changed. + // + string plan; + bool print_plan (false); + if (o.print_only () || !o.yes ()) { for (const build_package& p: reverse_iterate (pkgs)) @@ -1467,6 +1475,10 @@ namespace bpkg { // This is a dependent needing reconfiguration. // + // This is an implicit reconfiguration which requires the plan to be + // printed. Will flag that later when composing the list of + // prerequisites. + // assert (sp != nullptr && p.reconfigure ()); update_dependents = true; act = "reconfigure " + sp->name; @@ -1488,7 +1500,7 @@ namespace bpkg // if (!p.reconfigure () && sp->state == package_state::configured && - find (names.begin (), names.end (), sp->name) == names.end ()) + !p.user_selection ()) continue; act = p.system @@ -1498,12 +1510,16 @@ namespace bpkg : "build "; } else + { act = p.system ? "reconfigure " : sp->version < p.available_version () ? "upgrade " : "downgrade "; + print_plan = true; + } + act += p.available_name (); cause = "required by"; } @@ -1513,6 +1529,13 @@ namespace bpkg { for (const string& n: p.required_by) rb += ' ' + n; + + // If not user-selected, then there should be another (implicit) + // reason for the action. + // + assert (!rb.empty ()); + + print_plan = true; } if (!rb.empty ()) @@ -1523,16 +1546,19 @@ namespace bpkg else if (verb) // Print indented for better visual separation. // - text << " " << act; + plan += (plan.empty () ? " " : "\n ") + act; } } if (o.print_only ()) return 0; + if (print_plan) + text << plan; + // Ask the user if we should continue. // - if (!(o.yes () || yn_prompt ("continue? [Y/n]", 'y'))) + if (!(o.yes () || !print_plan || yn_prompt ("continue? [Y/n]", 'y'))) return 1; // Figure out if we also should update dependents. @@ -1846,7 +1872,7 @@ namespace bpkg const shared_ptr<selected_package>& sp (p.selected); if (!sp->system () && // System package doesn't need update. - find (names.begin (), names.end (), sp->name) != names.end ()) + p.user_selection ()) upkgs.push_back (pkg_command_vars {sp, strings ()}); } diff --git a/bpkg/pkg-drop.cxx b/bpkg/pkg-drop.cxx index d623b68..065d652 100644 --- a/bpkg/pkg-drop.cxx +++ b/bpkg/pkg-drop.cxx @@ -299,11 +299,12 @@ namespace bpkg bool print_only, bool disfigure_only, bool yes, - bool no) + bool no, + bool print_plan) { // Print what we are going to do, then ask for the user's confirmation. // - if (print_only || !(yes || no)) + if (print_only || !(yes || no || !print_plan)) { for (const drop_package& dp: pkgs) { @@ -328,7 +329,7 @@ namespace bpkg // Ask the user if we should continue. // - if (no || !(yes || yn_prompt ("continue? [Y/n]", 'y'))) + if (no || !(yes || !print_plan || yn_prompt ("continue? [Y/n]", 'y'))) return 1; // All that's left to do is first disfigure configured packages and @@ -433,6 +434,12 @@ namespace bpkg // drop_packages pkgs; bool drop_prq (false); + + // Print the plan and ask for the user's confirmation only if there are + // additional packages (such as dependents or prerequisites of the + // explicitly listed packages) to be dropped. + // + bool print_plan (false); { transaction t (db.begin ()); @@ -486,6 +493,8 @@ namespace bpkg if (o.no () || !yn_prompt ("drop dependent packages? [y/N]", 'n')) return 1; + + print_plan = true; } // Collect all the prerequisites that are not held. These will be @@ -541,6 +550,9 @@ namespace bpkg } drop_prq = yn_prompt ("drop prerequisite packages? [Y/n]", 'y'); + + if (drop_prq) + print_plan = true; } t.commit (); @@ -554,7 +566,8 @@ namespace bpkg o.print_only (), o.disfigure_only (), o.yes (), - o.no ()); + o.no (), + print_plan); } set<shared_ptr<selected_package>> @@ -623,7 +636,8 @@ namespace bpkg false, // Print-only (too late for that). false, // Disfigure-only (could be an option). true, // Yes (don't print the plan or prompt). - false); // No (we already said yes). + false, // No (we already said yes). + false); // Don't print the plan (just to reiterate). set<shared_ptr<selected_package>> r; for (const drop_package& dp: pkgs) |