aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-22 12:28:17 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-22 12:28:17 +0000
commit721c4c194a49c4f131af590d56edd056bfcb5465 (patch)
treefd1605b86a0a3d5a5cf04d7efbd951b8c3e5660d
parent9e989c9c78e96e4595a6426e975ba301580217dc (diff)
downloadpaludis-721c4c194a49c4f131af590d56edd056bfcb5465.tar.gz
paludis-721c4c194a49c4f131af590d56edd056bfcb5465.tar.xz
Add --list-categories. Rename list_repositories files -> list and include both repository and category listing functions.
-rw-r--r--src/Makefile.am2
-rw-r--r--src/command_line.cc1
-rw-r--r--src/command_line.hh3
-rw-r--r--src/list.cc (renamed from src/list_repositories.cc)39
-rw-r--r--src/list.hh (renamed from src/list_repositories.hh)5
-rw-r--r--src/paludis.cc13
6 files changed, 57 insertions, 6 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 446f540..7e28f45 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,7 +9,7 @@ paludis_SOURCES = \
command_line.hh command_line.cc \
colour.hh colour.cc \
install.hh install.cc \
- list_repositories.hh list_repositories.cc \
+ list.hh list.cc \
query.hh query.cc \
paludis.cc
diff --git a/src/command_line.cc b/src/command_line.cc
index d0802c7..3cab207 100644
--- a/src/command_line.cc
+++ b/src/command_line.cc
@@ -27,6 +27,7 @@ CommandLine::CommandLine() :
a_query(&action_args, "query", 'q', "Query for package information"),
a_install(&action_args, "install", 'i', "Install one or more packages"),
a_list_repositories(&action_args, "list-repositories", '\0', "List available repositories"),
+ a_list_categories(&action_args, "list-categories", '\0', "List available categories"),
a_version(&action_args, "version", 'V', "Display program version"),
a_help(&action_args, "help", 'h', "Display program help"),
diff --git a/src/command_line.hh b/src/command_line.hh
index 7d808bb..d91aa23 100644
--- a/src/command_line.hh
+++ b/src/command_line.hh
@@ -60,6 +60,9 @@ class CommandLine :
/// --list-repositories
paludis::args::SwitchArg a_list_repositories;
+ /// --list-categories
+ paludis::args::SwitchArg a_list_categories;
+
/// --version
paludis::args::SwitchArg a_version;
diff --git a/src/list_repositories.cc b/src/list.cc
index 01201fe..241420a 100644
--- a/src/list_repositories.cc
+++ b/src/list.cc
@@ -18,15 +18,18 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "list_repositories.hh"
+#include "list.hh"
#include "colour.hh"
#include <paludis/paludis.hh>
#include <iostream>
#include <iomanip>
+#include <map>
+#include <list>
namespace p = paludis;
-int do_list_repositories()
+int
+do_list_repositories()
{
p::Context context("When performing list-repositories action from command line:");
p::Environment * const env(p::DefaultEnvironment::get_instance());
@@ -47,3 +50,35 @@ int do_list_repositories()
return 0;
}
+int
+do_list_categories()
+{
+ p::Context context("When performing list-categories action from command line:");
+ p::Environment * const env(p::DefaultEnvironment::get_instance());
+
+ std::map<p::CategoryNamePart, std::list<p::RepositoryName> > cats;
+
+ for (p::IndirectIterator<p::PackageDatabase::RepositoryIterator, const p::Repository>
+ r(env->package_db()->begin_repositories()), r_end(env->package_db()->end_repositories()) ;
+ r != r_end ; ++r)
+ {
+ p::CategoryNamePartCollection::ConstPointer cat_names(r->category_names());
+ for (p::CategoryNamePartCollection::Iterator c(cat_names->begin()), c_end(cat_names->end()) ;
+ c != c_end ; ++c)
+ cats[*c].push_back(r->name());
+ }
+
+ for (std::map<p::CategoryNamePart, std::list<p::RepositoryName > >::const_iterator
+ c(cats.begin()), c_end(cats.end()) ; c != c_end ; ++c)
+ {
+ std::cout << "* " << colour(cl_package_name, c->first) << std::endl;
+ std::cout << " " << std::setw(22) << std::left << "found in:" <<
+ std::setw(0) << " ";
+ std::copy(c->second.begin(), c->second.end(),
+ std::ostream_iterator<p::RepositoryName>(std::cout, " "));
+ std::cout << std::endl;
+ std::cout << std::endl;
+ }
+
+ return 0;
+}
diff --git a/src/list_repositories.hh b/src/list.hh
index afa64c7..4888c31 100644
--- a/src/list_repositories.hh
+++ b/src/list.hh
@@ -22,10 +22,13 @@
#define PALUDIS_GUARD_SRC_LIST_REPOSITORIES_HH 1
/** \file
- * Declaration for the do_list_repositories function.
+ * Declaration for the do_list_repositories and do_list_categories functions.
*/
/// Handle --list-repositories.
int do_list_repositories();
+/// Handle --list-categories.
+int do_list_categories();
+
#endif
diff --git a/src/paludis.cc b/src/paludis.cc
index 8725ae5..8df9fe0 100644
--- a/src/paludis.cc
+++ b/src/paludis.cc
@@ -20,7 +20,7 @@
#include <paludis/paludis.hh>
#include "src/query.hh"
#include "src/install.hh"
-#include "src/list_repositories.hh"
+#include "src/list.hh"
#include "src/command_line.hh"
#include <iostream>
@@ -67,7 +67,8 @@ main(int argc, char *argv[])
if (1 != (CommandLine::get_instance()->a_query.specified() +
CommandLine::get_instance()->a_version.specified() +
CommandLine::get_instance()->a_install.specified() +
- CommandLine::get_instance()->a_list_repositories.specified()))
+ CommandLine::get_instance()->a_list_repositories.specified() +
+ CommandLine::get_instance()->a_list_categories.specified()))
throw DoHelp("you should specify exactly one action");
if (CommandLine::get_instance()->a_version.specified())
@@ -97,6 +98,14 @@ main(int argc, char *argv[])
return do_list_repositories();
}
+ if (CommandLine::get_instance()->a_list_categories.specified())
+ {
+ if (! CommandLine::get_instance()->empty())
+ throw DoHelp("list-categories action takes no parameters");
+
+ return do_list_categories();
+ }
+
throw p::InternalError(__PRETTY_FUNCTION__, "no action?");
}
catch (const DoVersion &)