aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-03 16:47:22 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-03 16:47:22 +0000
commit4097316c87ab0f2ee47a762b4ce7466f4798fc1c (patch)
tree79979c368d899167bdf8e5e7a8b8c4a91551b9f9
parent1ca0470803a7cb26a4b89bd9f7fc636b69c1c04b (diff)
downloadpaludis-4097316c87ab0f2ee47a762b4ce7466f4798fc1c.tar.gz
paludis-4097316c87ab0f2ee47a762b4ce7466f4798fc1c.tar.xz
Add --list-packages
-rw-r--r--src/command_line.cc1
-rw-r--r--src/command_line.hh3
-rw-r--r--src/list.cc35
-rw-r--r--src/list.hh3
-rw-r--r--src/paludis.cc11
5 files changed, 52 insertions, 1 deletions
diff --git a/src/command_line.cc b/src/command_line.cc
index 357b506..728d32a 100644
--- a/src/command_line.cc
+++ b/src/command_line.cc
@@ -27,6 +27,7 @@ CommandLine::CommandLine() :
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_list_packages(&action_args, "list-packages", '\0', "List available packages"),
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 af5181f..99adf2e 100644
--- a/src/command_line.hh
+++ b/src/command_line.hh
@@ -62,6 +62,9 @@ class CommandLine :
/// --list-categories
paludis::args::SwitchArg a_list_categories;
+ /// --list-packages
+ paludis::args::SwitchArg a_list_packages;
+
/// --version
paludis::args::SwitchArg a_version;
diff --git a/src/list.cc b/src/list.cc
index 5b30a6e..295bd2d 100644
--- a/src/list.cc
+++ b/src/list.cc
@@ -78,3 +78,38 @@ do_list_categories()
return 0;
}
+
+int
+do_list_packages()
+{
+ p::Context context("When performing list-packages action from command line:");
+ p::Environment * const env(p::DefaultEnvironment::get_instance());
+
+ std::map<p::QualifiedPackageName, std::list<p::RepositoryName> > pkgs;
+
+ for (p::IndirectIterator<p::PackageDatabase::RepositoryIterator, const p::Repository>
+ r(env->package_database()->begin_repositories()), r_end(env->package_database()->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)
+ {
+ p::QualifiedPackageNameCollection::ConstPointer pkg_names(r->package_names(*c));
+ for (p::QualifiedPackageNameCollection::Iterator p(pkg_names->begin()), p_end(pkg_names->end()) ;
+ p != p_end ; ++p)
+ pkgs[*p].push_back(r->name());
+ }
+ }
+
+ for (std::map<p::QualifiedPackageName, std::list<p::RepositoryName > >::const_iterator
+ p(pkgs.begin()), p_end(pkgs.end()) ; p != p_end ; ++p)
+ {
+ std::cout << "* " << colour(cl_package_name, p->first) << std::endl;
+ std::cout << " " << std::setw(22) << std::left << "found in:" <<
+ std::setw(0) << " " << p::join(p->second.begin(), p->second.end(), ", ") << std::endl;
+ std::cout << std::endl;
+ }
+
+ return 0;
+}
diff --git a/src/list.hh b/src/list.hh
index 08bfe61..2c7a2d1 100644
--- a/src/list.hh
+++ b/src/list.hh
@@ -30,4 +30,7 @@ int do_list_repositories();
/// Handle --list-categories.
int do_list_categories();
+/// Handle --list-packages.
+int do_list_packages();
+
#endif
diff --git a/src/paludis.cc b/src/paludis.cc
index 8dab2dc..11d5b02 100644
--- a/src/paludis.cc
+++ b/src/paludis.cc
@@ -68,7 +68,8 @@ main(int argc, char *argv[])
CommandLine::get_instance()->a_version.specified() +
CommandLine::get_instance()->a_install.specified() +
CommandLine::get_instance()->a_list_repositories.specified() +
- CommandLine::get_instance()->a_list_categories.specified()))
+ CommandLine::get_instance()->a_list_categories.specified() +
+ CommandLine::get_instance()->a_list_packages.specified()))
throw DoHelp("you should specify exactly one action");
if (CommandLine::get_instance()->a_version.specified())
@@ -106,6 +107,14 @@ main(int argc, char *argv[])
return do_list_categories();
}
+ if (CommandLine::get_instance()->a_list_packages.specified())
+ {
+ if (! CommandLine::get_instance()->empty())
+ throw DoHelp("list-packages action takes no parameters");
+
+ return do_list_packages();
+ }
+
throw p::InternalError(__PRETTY_FUNCTION__, "no action?");
}
catch (const DoVersion &)