diff options
author | 2011-06-27 18:50:34 -0700 | |
---|---|---|
committer | 2011-06-30 10:27:28 +0100 | |
commit | b6f5d29a9561fd16a28b57850a10c605cd9d5c90 (patch) | |
tree | 4f59a226cd40e459a230d75a9501d3ef2b5c1709 | |
parent | 21af4bf5f51e7e146ccd52b7c24f42ab12bea98c (diff) | |
download | paludis-b6f5d29a9561fd16a28b57850a10c605cd9d5c90.tar.gz paludis-b6f5d29a9561fd16a28b57850a10c605cd9d5c90.tar.xz |
Implement --matching for 'owner' and 'print-owners' cave subcommands
-rw-r--r-- | src/clients/cave/cmd_owner.cc | 28 | ||||
-rw-r--r-- | src/clients/cave/cmd_print_owners.cc | 27 | ||||
-rw-r--r-- | src/clients/cave/owner_common.cc | 3 | ||||
-rw-r--r-- | src/clients/cave/owner_common.hh | 4 |
4 files changed, 53 insertions, 9 deletions
diff --git a/src/clients/cave/cmd_owner.cc b/src/clients/cave/cmd_owner.cc index c8f30f46b..244b8da9e 100644 --- a/src/clients/cave/cmd_owner.cc +++ b/src/clients/cave/cmd_owner.cc @@ -27,7 +27,11 @@ #include <paludis/action.hh> #include <paludis/args/args.hh> #include <paludis/args/do_help.hh> +#include <paludis/dep_spec.hh> +#include <paludis/filter.hh> +#include <paludis/user_dep_spec.hh> #include <paludis/util/indirect_iterator-impl.hh> +#include <paludis/util/make_null_shared_ptr.hh> #include <paludis/util/wrapped_forward_iterator.hh> #include <paludis/util/stringify.hh> @@ -65,6 +69,7 @@ namespace args::ArgsGroup g_owner_options; args::EnumArg a_type; args::SwitchArg a_dereference; + args::StringSetArg a_matching; OwnerCommandLine() : g_owner_options(main_options_section(), "Owner options", "Alter how the search is performed."), @@ -76,9 +81,12 @@ namespace ("partial", 'p', "Partial match"), "auto"), a_dereference(&g_owner_options, "dereference", 'd', "If the pattern is a path that exists and is a symbolic link, " - "dereference it recursively, and then search for the real path.", true) + "dereference it recursively, and then search for the real path.", true), + a_matching(&g_owner_options, "matching", 'm', "Show only IDs matching this spec. If specified multiple " + "times, only IDs matching every spec are selected.", + args::StringSetArg::StringSetArgOptions()) { - add_usage_line("[ --type algorithm ] pattern"); + add_usage_line("[ --type algorithm ] [ --matching spec ] pattern"); } }; @@ -106,8 +114,20 @@ OwnerCommand::run( if (std::distance(cmdline.begin_parameters(), cmdline.end_parameters()) != 1) throw args::DoHelp("owner takes exactly one parameter"); - return owner_common(env, cmdline.a_type.argument(), *cmdline.begin_parameters(), - cmdline.a_dereference.specified(), &format_id); + Filter matches((filter::All())); + if (cmdline.a_matching.specified()) + { + for (args::StringSetArg::ConstIterator m(cmdline.a_matching.begin_args()), + m_end(cmdline.a_matching.end_args()) ; + m != m_end ; ++m) + { + PackageDepSpec s(parse_user_package_dep_spec(*m, env.get(), { updso_allow_wildcards })); + matches = filter::And(matches, filter::Matches(s, make_null_shared_ptr(), { })); + } + } + + return owner_common(env, cmdline.a_type.argument(), matches, + *cmdline.begin_parameters(), cmdline.a_dereference.specified(), &format_id); } std::shared_ptr<args::ArgsHandler> diff --git a/src/clients/cave/cmd_print_owners.cc b/src/clients/cave/cmd_print_owners.cc index c7636c575..a7b5f227a 100644 --- a/src/clients/cave/cmd_print_owners.cc +++ b/src/clients/cave/cmd_print_owners.cc @@ -23,6 +23,10 @@ #include "owner_common.hh" #include <paludis/args/args.hh> #include <paludis/args/do_help.hh> +#include <paludis/dep_spec.hh> +#include <paludis/filter.hh> +#include <paludis/user_dep_spec.hh> +#include <paludis/util/make_null_shared_ptr.hh> #include <iostream> #include <cstdlib> @@ -53,6 +57,7 @@ namespace args::ArgsGroup g_owner_options; args::EnumArg a_type; + args::StringSetArg a_matching; PrintOwnersCommandLine() : g_owner_options(main_options_section(), "Owner options", "Alter how the search is performed."), @@ -62,9 +67,12 @@ namespace ("basename", "Basename match") ("full", "Full match") ("partial", "Partial match"), - "auto") + "auto"), + a_matching(&g_owner_options, "matching", 'm', "Show only IDs matching this spec. If specified multiple " + "times, only IDs matching every spec are selected.", + args::StringSetArg::StringSetArgOptions()) { - add_usage_line("[ --type algorithm ] pattern"); + add_usage_line("[ --type algorithm ] [ --matching spec ] pattern"); } }; @@ -92,7 +100,20 @@ PrintOwnersCommand::run( if (std::distance(cmdline.begin_parameters(), cmdline.end_parameters()) != 1) throw args::DoHelp("print-owners takes exactly one parameter"); - return owner_common(env, cmdline.a_type.argument(), *cmdline.begin_parameters(), false, &print_package_id); + Filter matches((filter::All())); + if (cmdline.a_matching.specified()) + { + for (args::StringSetArg::ConstIterator m(cmdline.a_matching.begin_args()), + m_end(cmdline.a_matching.end_args()) ; + m != m_end ; ++m) + { + PackageDepSpec s(parse_user_package_dep_spec(*m, env.get(), { updso_allow_wildcards })); + matches = filter::And(matches, filter::Matches(s, make_null_shared_ptr(), { })); + } + } + + return owner_common(env, cmdline.a_type.argument(), matches, + *cmdline.begin_parameters(), false, &print_package_id); } std::shared_ptr<args::ArgsHandler> diff --git a/src/clients/cave/owner_common.cc b/src/clients/cave/owner_common.cc index 7032174ea..66f974ea9 100644 --- a/src/clients/cave/owner_common.cc +++ b/src/clients/cave/owner_common.cc @@ -61,6 +61,7 @@ int paludis::cave::owner_common( const std::shared_ptr<Environment> & env, const std::string & type, + const Filter & matching, const std::string & q, const bool dereference, const std::function<void (const std::shared_ptr<const PackageID> &)> & callback) @@ -100,7 +101,7 @@ paludis::cave::owner_common( } std::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(generator::All() | - filter::InstalledAtRoot(env->preferred_root_key()->parse_value()))]); + filter::InstalledAtRoot(env->preferred_root_key()->parse_value()) | matching )]); for (PackageIDSequence::ConstIterator p(ids->begin()), p_end(ids->end()); p != p_end; ++p) { diff --git a/src/clients/cave/owner_common.hh b/src/clients/cave/owner_common.hh index 3181fd725..6f958eb40 100644 --- a/src/clients/cave/owner_common.hh +++ b/src/clients/cave/owner_common.hh @@ -24,6 +24,7 @@ #include <paludis/package_id-fwd.hh> #include <paludis/environment-fwd.hh> +#include <paludis/filter.hh> #include <string> #include <memory> #include <functional> @@ -34,7 +35,8 @@ namespace paludis { int owner_common( const std::shared_ptr<Environment> & env, - const std::string & match, + const std::string & type, + const Filter & matching, const std::string & query, const bool dereference, const std::function<void (const std::shared_ptr<const PackageID> &)> &); |