diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-05-17 13:20:32 +0200 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-05-17 16:22:42 +0300 |
commit | 3908754edadb9afbe0f977788cc34456cbdffc5a (patch) | |
tree | d820f098750b8492dac9fdb5be6d26bea4edb39a /bpkg/pkg-command.cxx | |
parent | 2ea3d11ac1d5b6069268709ca0125d2e90377d93 (diff) |
Add support for --all|-a to pkg-{update,clean,test,install,uninstall}
Diffstat (limited to 'bpkg/pkg-command.cxx')
-rw-r--r-- | bpkg/pkg-command.cxx | 100 |
1 files changed, 72 insertions, 28 deletions
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<pkg_command_vars> ps; { @@ -188,34 +202,64 @@ namespace bpkg // session ses; - while (args.more ()) + auto add = [&ps, recursive, immediate] ( + const shared_ptr<selected_package>& 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<selected_package> p (db.find<selected_package> (n)); + using query = query<selected_package>; - 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<selected_package> p: + pointer_result (db.query<selected_package> (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<selected_package> p (db.find<selected_package> (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 (); |