aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-23 09:25:47 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-23 09:25:47 +0100
commit7be6e2a6a627f001d26784fc514f462d6bfb7a82 (patch)
treeeff659db7cbbf43eeacddc3805f700866608965d
parentba41e2953d25dc8f9db41555cea2fbb68774613c (diff)
downloadpaludis-7be6e2a6a627f001d26784fc514f462d6bfb7a82.tar.gz
paludis-7be6e2a6a627f001d26784fc514f462d6bfb7a82.tar.xz
print-id-executables --all --best
Fixes: ticket:962
-rw-r--r--src/clients/cave/cmd_executables.cc2
-rw-r--r--src/clients/cave/cmd_print_id_executables.cc12
-rw-r--r--src/clients/cave/executables_common.cc26
-rw-r--r--src/clients/cave/executables_common.hh4
4 files changed, 30 insertions, 14 deletions
diff --git a/src/clients/cave/cmd_executables.cc b/src/clients/cave/cmd_executables.cc
index 3b08eb7..3b32af1 100644
--- a/src/clients/cave/cmd_executables.cc
+++ b/src/clients/cave/cmd_executables.cc
@@ -94,7 +94,7 @@ ExecutablesCommand::run(
if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
throw args::DoHelp("executables takes exactly one parameter");
- return executables_common(env, *cmdline.begin_parameters(), &format_fsentry);
+ return executables_common(env, *cmdline.begin_parameters(), &format_fsentry, true, false);
}
std::shared_ptr<args::ArgsHandler>
diff --git a/src/clients/cave/cmd_print_id_executables.cc b/src/clients/cave/cmd_print_id_executables.cc
index 9607d69..80b8c88 100644
--- a/src/clients/cave/cmd_print_id_executables.cc
+++ b/src/clients/cave/cmd_print_id_executables.cc
@@ -60,7 +60,14 @@ namespace
"No formating is used, making the script suitable for parsing by scripts.";
}
- PrintIDExecutablesCommandLine()
+ args::ArgsGroup g_spec_options;
+ args::SwitchArg a_all;
+ args::SwitchArg a_best;
+
+ PrintIDExecutablesCommandLine() :
+ g_spec_options(main_options_section(), "Spec Options", "Alter how the supplied spec is used."),
+ a_all(&g_spec_options, "all", 'a', "If the spec matches multiple IDs, display all matches.", true),
+ a_best(&g_spec_options, "best", 'b', "If the spec matches multiple IDs, select the best ID rather than giving an error.", true)
{
add_usage_line("spec");
}
@@ -90,7 +97,8 @@ PrintIDExecutablesCommand::run(
if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
throw args::DoHelp("print-id-executables takes exactly one parameter");
- return executables_common(env, *cmdline.begin_parameters(), &print_fsentry);
+ return executables_common(env, *cmdline.begin_parameters(), &print_fsentry, cmdline.a_all.specified(),
+ cmdline.a_best.specified());
}
std::shared_ptr<args::ArgsHandler>
diff --git a/src/clients/cave/executables_common.cc b/src/clients/cave/executables_common.cc
index f54a7d3..7378214 100644
--- a/src/clients/cave/executables_common.cc
+++ b/src/clients/cave/executables_common.cc
@@ -19,6 +19,7 @@
*/
#include "executables_common.hh"
+#include "exceptions.hh"
#include <paludis/contents.hh>
#include <paludis/environment.hh>
#include <paludis/filter.hh>
@@ -105,29 +106,34 @@ int
paludis::cave::executables_common(
const std::shared_ptr<Environment> & env,
const std::string & param,
- const std::function<void (const FSEntry &)> & displayer)
+ const std::function<void (const FSEntry &)> & displayer,
+ const bool all,
+ const bool best)
{
+ PackageDepSpec spec(parse_user_package_dep_spec(param, env.get(), { updso_allow_wildcards },
+ filter::InstalledAtRoot(env->preferred_root_key()->value())));
+
std::shared_ptr<const PackageIDSequence> entries(
- (*env)[selection::AllVersionsSorted(generator::Matches(
- PackageDepSpec(parse_user_package_dep_spec(
- param, env.get(),
- { updso_allow_wildcards },
- filter::InstalledAtRoot(env->preferred_root_key()->value()))),
- { }) | filter::InstalledAtRoot(env->preferred_root_key()->value()))]);
+ (*env)[selection::AllVersionsSorted(generator::Matches(spec, { }) |
+ filter::InstalledAtRoot(env->preferred_root_key()->value()))]);
if (entries->empty())
throw NoSuchPackageError(param);
+ if ((! best) && (! all) && (next(entries->begin()) != entries->end()))
+ throw BeMoreSpecific(spec, entries);
+
const std::string path(getenv_or_error("PATH"));
std::set<std::string> paths;
tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(path, ":", "", std::inserter(paths, paths.begin()));
ExecutablesDisplayer ed(paths, displayer);
- for (PackageIDSequence::ConstIterator t(entries->begin()), t_end(entries->end()) ; t != t_end ; ++t)
+ for (auto i(best ? entries->last() : entries->begin()), i_end(entries->end()) ;
+ i != i_end ; ++i)
{
- if ((*t)->contents_key())
+ if ((*i)->contents_key())
{
- std::shared_ptr<const Contents> contents((*t)->contents_key()->value());
+ std::shared_ptr<const Contents> contents((*i)->contents_key()->value());
std::for_each(indirect_iterator(contents->begin()), indirect_iterator(contents->end()), accept_visitor(ed));
}
}
diff --git a/src/clients/cave/executables_common.hh b/src/clients/cave/executables_common.hh
index 1de8078..e2364d8 100644
--- a/src/clients/cave/executables_common.hh
+++ b/src/clients/cave/executables_common.hh
@@ -34,7 +34,9 @@ namespace paludis
int executables_common(
const std::shared_ptr<Environment> & env,
const std::string &,
- const std::function<void (const FSEntry &)> &);
+ const std::function<void (const FSEntry &)> &,
+ const bool all,
+ const bool best);
}
}