aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Alexander Færøy <ahf@0x90.dk> 2008-11-15 23:10:36 +0100
committerAvatar Alexander Færøy <ahf@0x90.dk> 2008-11-15 23:10:36 +0100
commit90cf6700539afc237b5d2511f7f0a928dff7220c (patch)
tree35f28178b2793265e1dc1062c1ea6ae1b15376ce
parent2b72c6d42c4588709074fee37a7d50acb5df0f78 (diff)
downloadpaludis-90cf6700539afc237b5d2511f7f0a928dff7220c.tar.gz
paludis-90cf6700539afc237b5d2511f7f0a928dff7220c.tar.xz
Add cave print-repositories.
-rw-r--r--src/clients/cave/Makefile.am2
-rw-r--r--src/clients/cave/cmd_print_repositories.cc118
-rw-r--r--src/clients/cave/cmd_print_repositories.hh44
-rw-r--r--src/clients/cave/command_factory.cc2
4 files changed, 166 insertions, 0 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 30f69a6..58d4a7e 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -22,6 +22,7 @@ command_MANS = \
cave-print-id-contents.1 \
cave-print-id-metadata.1 \
cave-print-ids.1 \
+ cave-print-repositories.1 \
cave-show.1 \
cave-sync.1
@@ -69,6 +70,7 @@ libcave_a_SOURCES = \
cmd_print_environment_metadata.cc cmd_print_environment_metadata.hh \
cmd_print_id_metadata.cc cmd_print_id_metadata.hh \
cmd_print_ids.cc cmd_print_ids.hh \
+ cmd_print_repositories.cc cmd_print_repositories.hh \
cmd_show.cc cmd_show.hh \
cmd_sync.cc cmd_sync.hh \
exceptions.cc exceptions.hh \
diff --git a/src/clients/cave/cmd_print_repositories.cc b/src/clients/cave/cmd_print_repositories.cc
new file mode 100644
index 0000000..9d2abf5
--- /dev/null
+++ b/src/clients/cave/cmd_print_repositories.cc
@@ -0,0 +1,118 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Alexander Færøy
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "cmd_print_repositories.hh"
+
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_database.hh>
+#include <paludis/repository.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/metadata_key.hh>
+
+#include <set>
+#include <iostream>
+#include <algorithm>
+#include <cstdlib>
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct PrintRepositoriesCommandLine :
+ args::ArgsHandler
+ {
+ virtual std::string app_name() const
+ {
+ return "cave print-repositories";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Prints a list of repositories.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Prints a list of repositories. No formatting is used, making the output suitable for "
+ "parsing by scripts.";
+ }
+
+ args::ArgsGroup g_filters;
+ args::StringSetArg a_repository_format;
+
+ PrintRepositoriesCommandLine() :
+ g_filters(this, "Filters", "Filter the output."),
+ a_repository_format(&g_filters, "format", '\0', "Show only repositories of a specific format")
+ {
+ add_usage_line("[ --format type ]");
+ }
+ };
+}
+
+int
+PrintRepositoriesCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ PrintRepositoriesCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_PRINT_REPOSITORIES_OPTIONS", "CAVE_PRINT_REPOSITORIES_CMDLINE");
+
+ if (cmdline.begin_parameters() != cmdline.end_parameters())
+ throw args::DoHelp("print-repositories takes no parameters");
+
+ std::set<RepositoryName, RepositoryNameComparator> repository_names;
+
+ for (IndirectIterator<PackageDatabase::RepositoryConstIterator, const Repository>
+ r(env->package_database()->begin_repositories()), r_end(env->package_database()->end_repositories());
+ r != r_end; ++r)
+ {
+ if (cmdline.a_repository_format.specified())
+ {
+ if (r->format_key())
+ {
+ if (cmdline.a_repository_format.end_args() == std::find(cmdline.a_repository_format.begin_args(), cmdline.a_repository_format.end_args(),
+ r->format_key()->value()))
+ continue;
+
+ repository_names.insert(r->name());
+ }
+ }
+ else
+ repository_names.insert(r->name());
+ }
+
+ std::copy(repository_names.begin(), repository_names.end(), std::ostream_iterator<RepositoryName>(cout, "\n"));
+
+ return EXIT_SUCCESS;
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+PrintRepositoriesCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new PrintRepositoriesCommandLine);
+}
diff --git a/src/clients/cave/cmd_print_repositories.hh b/src/clients/cave/cmd_print_repositories.hh
new file mode 100644
index 0000000..6851c04
--- /dev/null
+++ b/src/clients/cave/cmd_print_repositories.hh
@@ -0,0 +1,44 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Alexander Færøy
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_REPOSITORIES_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_REPOSITORIES_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE PrintRepositoriesCommand :
+ public Command
+ {
+ public:
+ int run(
+ const std::tr1::shared_ptr<Environment> &,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ );
+
+ std::tr1::shared_ptr<args::ArgsHandler> make_doc_cmdline();
+ };
+ }
+}
+
+
+#endif
diff --git a/src/clients/cave/command_factory.cc b/src/clients/cave/command_factory.cc
index a71134e..48128ee 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -31,6 +31,7 @@
#include "cmd_print_environment_metadata.hh"
#include "cmd_print_id_contents.hh"
#include "cmd_print_id_metadata.hh"
+#include "cmd_print_repositories.hh"
#include "cmd_print_ids.hh"
#include "cmd_show.hh"
#include "cmd_sync.hh"
@@ -67,6 +68,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("print-id-contents", make_command<PrintIDContentsCommand>));
_imp->handlers.insert(std::make_pair("print-id-metadata", make_command<PrintIDMetadataCommand>));
_imp->handlers.insert(std::make_pair("print-ids", make_command<PrintIDsCommand>));
+ _imp->handlers.insert(std::make_pair("print-repositories", make_command<PrintRepositoriesCommand>));
_imp->handlers.insert(std::make_pair("show", make_command<ShowCommand>));
_imp->handlers.insert(std::make_pair("sync", make_command<SyncCommand>));
}