aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Alexander Færøy <ahf@0x90.dk> 2008-11-16 11:43:17 +0100
committerAvatar Alexander Færøy <ahf@0x90.dk> 2008-11-16 11:43:17 +0100
commit5917d67b242110ca0704ab0537eee1eab4a62e04 (patch)
tree8f7e44d4c576ef23d603c882847038d95a893abb
parent114f795d20592b1f0748649a16630a5c305da9d4 (diff)
downloadpaludis-5917d67b242110ca0704ab0537eee1eab4a62e04.tar.gz
paludis-5917d67b242110ca0704ab0537eee1eab4a62e04.tar.xz
Add cave print-sets.
-rw-r--r--src/clients/cave/Makefile.am4
-rw-r--r--src/clients/cave/cmd_print_sets.cc99
-rw-r--r--src/clients/cave/cmd_print_sets.hh44
-rw-r--r--src/clients/cave/command_factory.cc4
4 files changed, 148 insertions, 3 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 58d4a7e..8fca977 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -23,6 +23,7 @@ command_MANS = \
cave-print-id-metadata.1 \
cave-print-ids.1 \
cave-print-repositories.1 \
+ cave-print-sets.1 \
cave-show.1 \
cave-sync.1
@@ -71,6 +72,7 @@ libcave_a_SOURCES = \
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_print_sets.cc cmd_print_sets.hh \
cmd_show.cc cmd_show.hh \
cmd_sync.cc cmd_sync.hh \
exceptions.cc exceptions.hh \
@@ -92,10 +94,8 @@ libcave_a_SOURCES = \
# cmd_print_id_masks.cc \
# cmd_print_owners.cc \
# cmd_print_packages.cc \
-# cmd_print_repositories.cc \
# cmd_print_repository_formats.cc \
# cmd_print_repository_metadata.cc \
-# cmd_print_sets.cc \
# cmd_print_set.cc \
# cmd_print_sync_protocol_metadata.cc \
# cmd_print_sync_protocols.cc \
diff --git a/src/clients/cave/cmd_print_sets.cc b/src/clients/cave/cmd_print_sets.cc
new file mode 100644
index 0000000..9b50903
--- /dev/null
+++ b/src/clients/cave/cmd_print_sets.cc
@@ -0,0 +1,99 @@
+/* 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_sets.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/indirect_iterator-impl.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+
+#include <cstdlib>
+#include <iostream>
+#include <set>
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct PrintSetsCommandLine :
+ args::ArgsHandler
+ {
+ virtual std::string app_name() const
+ {
+ return "cave print-sets";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Prints a list of sets.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Prints a list of sets. No formatting is used, making the output suitable for "
+ "parsing by scripts.";
+ }
+ };
+}
+
+int
+PrintSetsCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ PrintSetsCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_PRINT_SETS_OPTIONS", "CAVE_PRINT_SETS_CMDLINE");
+
+ if (cmdline.begin_parameters() != cmdline.end_parameters())
+ throw args::DoHelp("print-sets takes no parameters");
+
+ std::set<SetName> sets;
+
+ for (IndirectIterator<PackageDatabase::RepositoryConstIterator, const Repository>
+ r(env->package_database()->begin_repositories()), r_end(env->package_database()->end_repositories());
+ r != r_end; ++r)
+ {
+ if ((*r).sets_interface() == 0)
+ continue;
+
+ std::tr1::shared_ptr<const SetNameSet> set_names((*r).sets_interface()->sets_list());
+
+ std::copy(set_names->begin(), set_names->end(), std::inserter(sets, sets.begin()));
+ }
+
+ std::copy(sets.begin(), sets.end(), std::ostream_iterator<SetName>(cout, "\n"));
+
+ return EXIT_SUCCESS;
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+PrintSetsCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new PrintSetsCommandLine);
+}
diff --git a/src/clients/cave/cmd_print_sets.hh b/src/clients/cave/cmd_print_sets.hh
new file mode 100644
index 0000000..cc75082
--- /dev/null
+++ b/src/clients/cave/cmd_print_sets.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_SETS_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_SETS_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE PrintSetsCommand :
+ 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 48128ee..becdc43 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -31,8 +31,9 @@
#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_print_repositories.hh"
+#include "cmd_print_sets.hh"
#include "cmd_show.hh"
#include "cmd_sync.hh"
@@ -69,6 +70,7 @@ CommandFactory::CommandFactory() :
_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("print-sets", make_command<PrintSetsCommand>));
_imp->handlers.insert(std::make_pair("show", make_command<ShowCommand>));
_imp->handlers.insert(std::make_pair("sync", make_command<SyncCommand>));
}