aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-10 12:42:23 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-10 12:42:23 +0100
commit19930e089cf5b7bf089855bed80471afe1064ee0 (patch)
tree09ace56c831068c7b7af5327f2b98ef3c70f0984
parentb1fd8585ccacf68c330a286931f7ad042d9a0f50 (diff)
downloadpaludis-19930e089cf5b7bf089855bed80471afe1064ee0.tar.gz
paludis-19930e089cf5b7bf089855bed80471afe1064ee0.tar.xz
Suggestions for cave
Fixes: ticket:856
-rw-r--r--src/clients/cave/exceptions.cc25
-rw-r--r--src/clients/cave/exceptions.hh8
2 files changed, 30 insertions, 3 deletions
diff --git a/src/clients/cave/exceptions.cc b/src/clients/cave/exceptions.cc
index f5c1e48..c207b2e 100644
--- a/src/clients/cave/exceptions.cc
+++ b/src/clients/cave/exceptions.cc
@@ -23,8 +23,10 @@
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/iterator_funcs.hh>
#include <paludis/package_id.hh>
#include <paludis/dep_spec.hh>
+#include <paludis/fuzzy_finder.hh>
using namespace paludis;
using namespace cave;
@@ -39,6 +41,16 @@ NothingMatching::NothingMatching(const std::string & name) throw () :
{
}
+NothingMatching::NothingMatching(const std::string & name, const std::string & extra_message) throw () :
+ Exception("Found nothing suitable matching '" + name + "'" + extra_message)
+{
+}
+
+NothingMatchingWithSuggestions::NothingMatchingWithSuggestions(const std::string & name, const std::string & suggestions) throw () :
+ NothingMatching(name, "; did you mean " + suggestions + "?")
+{
+}
+
BeMoreSpecific::BeMoreSpecific(const PackageDepSpec & spec, const std::shared_ptr<const PackageIDSequence> & s) throw () :
Exception("Found multiple suitable IDs matching '" + stringify(spec) + "': { '" + join(indirect_iterator(s->begin()),
indirect_iterator(s->end()), "', '") + "' }")
@@ -58,10 +70,17 @@ BadRepositoryForCommand::BadRepositoryForCommand(const RepositoryName & name, co
void
paludis::cave::nothing_matching_error(
- const Environment * const,
+ const Environment * const env,
const std::string & s,
- const Filter &)
+ const Filter & filter)
{
- throw NothingMatching(s);
+ FuzzyCandidatesFinder f(*env, s, filter);
+
+ if (f.begin() == f.end())
+ throw NothingMatching(s);
+ else if (next(f.begin()) == f.end())
+ throw NothingMatchingWithSuggestions(s, "'" + stringify(*f.begin()) + "'");
+ else
+ throw NothingMatchingWithSuggestions(s, "one of '" + join(f.begin(), f.end(), "', '") + "'");
}
diff --git a/src/clients/cave/exceptions.hh b/src/clients/cave/exceptions.hh
index 9f6ad27..7e42f39 100644
--- a/src/clients/cave/exceptions.hh
+++ b/src/clients/cave/exceptions.hh
@@ -38,6 +38,14 @@ namespace paludis
public:
NothingMatching(const PackageDepSpec &) throw ();
NothingMatching(const std::string &) throw ();
+ NothingMatching(const std::string &, const std::string &) throw ();
+ };
+
+ class PALUDIS_VISIBLE NothingMatchingWithSuggestions :
+ public NothingMatching
+ {
+ public:
+ NothingMatchingWithSuggestions(const std::string &, const std::string &) throw ();
};
class PALUDIS_VISIBLE BeMoreSpecific :