From 3908754edadb9afbe0f977788cc34456cbdffc5a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 May 2018 13:20:32 +0200 Subject: Add support for --all|-a to pkg-{update,clean,test,install,uninstall} --- bpkg/pkg-command.cxx | 100 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 28 deletions(-) (limited to 'bpkg/pkg-command.cxx') diff --git a/bpkg/pkg-command.cxx b/bpkg/pkg-command.cxx index 93e1779..5b1bb49 100644 --- a/bpkg/pkg-command.cxx +++ b/bpkg/pkg-command.cxx @@ -144,15 +144,11 @@ namespace bpkg const string& cmd_v, bool recursive, bool immediate, + bool all, cli::scanner& args) { tracer trace ("pkg_command"); - // We can as well count on the immediate/recursive option names. - // - if (immediate && recursive) - fail << "both --immediate|-i and --recursive|-r specified"; - const dir_path& c (o.directory ()); l4 ([&]{trace << "configuration: " << c;}); @@ -174,9 +170,27 @@ namespace bpkg strings cvars; read_vars (cvars); - if (!args.more ()) - fail << "package name argument expected" << - info << "run 'bpkg help pkg-" << cmd << "' for more information"; + // Check that options and arguments are consistent. + // + // Note that we can as well count on the option names that correspond to + // the immediate, recursive, and all parameters. + // + { + diag_record dr; + + if (immediate && recursive) + dr << fail << "both --immediate|-i and --recursive|-r specified"; + else if (all) + { + if (args.more ()) + dr << fail << "both --all|-a and package argument specified"; + } + else if (!args.more ()) + dr << fail << "package name argument expected"; + + if (!dr.empty ()) + dr << info << "run 'bpkg help pkg-" << cmd << "' for more information"; + } vector ps; { @@ -188,34 +202,64 @@ namespace bpkg // session ses; - while (args.more ()) + auto add = [&ps, recursive, immediate] ( + const shared_ptr& p, + strings vars) + { + ps.push_back (pkg_command_vars {p, move (vars)}); + + // Note that it can only be recursive or immediate but not both. + // + if (recursive || immediate) + collect_dependencies (p, recursive, ps); + }; + + if (all) { - string n (args.next ()); - shared_ptr p (db.find (n)); + using query = query; - if (p == nullptr) - fail << "package " << n << " does not exist in configuration " << c; + query q (query::hold_package && + query::state == "configured" && + query::substate != "system"); - if (p->state != package_state::configured) - fail << "package " << n << " is " << p->state << - info << "expected it to be configured"; + for (shared_ptr p: + pointer_result (db.query (q))) + { + l4 ([&]{trace << *p;}); - if (p->substate == package_substate::system) - fail << "cannot " << cmd << " system package " << n; + add (p, strings ()); + } - l4 ([&]{trace << *p;}); + if (ps.empty ()) + info << "nothing to " << cmd; + } + else + { + while (args.more ()) + { + string n (args.next ()); + shared_ptr p (db.find (n)); - // Read package-specific variables. - // - strings vars; - read_vars (vars); + if (p == nullptr) + fail << "package " << n << " does not exist in configuration " + << c; - ps.push_back (pkg_command_vars {p, move (vars)}); + if (p->state != package_state::configured) + fail << "package " << n << " is " << p->state << + info << "expected it to be configured"; - // Note that it can only be recursive or immediate but not both. - // - if (recursive || immediate) - collect_dependencies (p, recursive, ps); + if (p->substate == package_substate::system) + fail << "cannot " << cmd << " system package " << n; + + l4 ([&]{trace << *p;}); + + // Read package-specific variables. + // + strings vars; + read_vars (vars); + + add (p, move (vars)); + } } t.commit (); -- cgit v1.1