aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-19 16:15:11 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-19 16:15:11 +0100
commit9dba3665391f2e5f1f23914312d6f819e9d2d0ea (patch)
treea463c5fcc0e5951055ee8eafbfffdb5fcccb90c7
parent9905960eeebd62d0a96a8d65e60a017db5b7cb3d (diff)
downloadpaludis-9dba3665391f2e5f1f23914312d6f819e9d2d0ea.tar.gz
paludis-9dba3665391f2e5f1f23914312d6f819e9d2d0ea.tar.xz
cave print-set
Fixes: ticket:833
-rw-r--r--.gitignore1
-rw-r--r--doc/clients/Makefile.am1
-rw-r--r--src/clients/cave/Makefile.am2
-rw-r--r--src/clients/cave/cmd_print_set.cc158
-rw-r--r--src/clients/cave/cmd_print_set.hh43
-rw-r--r--src/clients/cave/command_factory.cc2
6 files changed, 207 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 0f45b64..84c2016 100644
--- a/.gitignore
+++ b/.gitignore
@@ -106,6 +106,7 @@ paludis-*.*.*.tar.bz2
/doc/clients/cave-print-packages.html
/doc/clients/cave-print-repositories.html
/doc/clients/cave-print-repository-formats.html
+/doc/clients/cave-print-set.html
/doc/clients/cave-print-sets.html
/doc/clients/cave-print-sync-protocols.html
/doc/clients/cave-purge.html
diff --git a/doc/clients/Makefile.am b/doc/clients/Makefile.am
index 66951ba..7969bab 100644
--- a/doc/clients/Makefile.am
+++ b/doc/clients/Makefile.am
@@ -51,6 +51,7 @@ CAVE_COMMANDS_HTML = \
cave-print-packages.html \
cave-print-repositories.html \
cave-print-repository-formats.html \
+ cave-print-set.html \
cave-print-sets.html \
cave-print-sync-protocols.html \
cave-purge.html \
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 37d7dcb..d113b4f 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -44,6 +44,7 @@ command_MANS = \
cave-print-packages.1 \
cave-print-repositories.1 \
cave-print-repository-formats.1 \
+ cave-print-set.1 \
cave-print-sets.1 \
cave-print-sync-protocols.1 \
cave-purge.1 \
@@ -122,6 +123,7 @@ libcave_a_SOURCES = \
cmd_print_packages.cc cmd_print_packages.hh \
cmd_print_repositories.cc cmd_print_repositories.hh \
cmd_print_repository_formats.cc cmd_print_repository_formats.hh \
+ cmd_print_set.cc cmd_print_set.hh \
cmd_print_sets.cc cmd_print_sets.hh \
cmd_print_sync_protocols.cc cmd_print_sync_protocols.hh \
cmd_purge.cc cmd_purge.hh \
diff --git a/src/clients/cave/cmd_print_set.cc b/src/clients/cave/cmd_print_set.cc
new file mode 100644
index 0000000..25b9eac
--- /dev/null
+++ b/src/clients/cave/cmd_print_set.cc
@@ -0,0 +1,158 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2010 Ciaran McCreesh
+ *
+ * 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_set.hh"
+#include "format_string.hh"
+#include "exceptions.hh"
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/name.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_database.hh>
+#include <paludis/repository.hh>
+#include <paludis/spec_tree.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/simple_visitor_cast.hh>
+#include <paludis/util/map.hh>
+#include <cstdlib>
+#include <iostream>
+#include <algorithm>
+#include <set>
+
+#include "command_command_line.hh"
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct PrintSetCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave print-set";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Prints a list of known sets.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Prints a list of known sets. No formatting is used, making the output suitable for "
+ "parsing by scripts.";
+ }
+
+ args::ArgsGroup g_display_options;
+ args::SwitchArg a_expand;
+
+ PrintSetCommandLine() :
+ g_display_options(main_options_section(), "Display Options", "Controls the output format."),
+ a_expand(&g_display_options, "expand", 'x', "Expand set contents recursively", true)
+ {
+ add_usage_line("[ --expand ] set");
+ }
+ };
+
+ struct SetPrinter
+ {
+ const std::tr1::shared_ptr<const Environment> env;
+ const PrintSetCommandLine & cmdline;
+ std::set<SetName> & recursing;
+
+ SetPrinter(const std::tr1::shared_ptr<const Environment> & e, const PrintSetCommandLine & c, std::set<SetName> & r) :
+ env(e),
+ cmdline(c),
+ recursing(r)
+ {
+ }
+
+ void visit(const SetSpecTree::NodeType<PackageDepSpec>::Type & node) const
+ {
+ cout << *node.spec() << endl;
+ }
+
+ void visit(const SetSpecTree::NodeType<NamedSetDepSpec>::Type & node) const
+ {
+ if (cmdline.a_expand.specified())
+ {
+ SetName name(node.spec()->name());
+ if (! recursing.insert(name).second)
+ throw RecursivelyDefinedSetError(stringify(name));
+
+ const std::tr1::shared_ptr<const SetSpecTree> set(env->set(name));
+ if (! set)
+ throw NoSuchSetError(stringify(name));
+
+ set->root()->accept(*this);
+
+ recursing.erase(name);
+ }
+ else
+ cout << *node.spec() << endl;
+ }
+
+ void visit(const SetSpecTree::NodeType<AllDepSpec>::Type & node) const
+ {
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this));
+ }
+ };
+}
+
+int
+PrintSetCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ PrintSetCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_PRINT_IDS_OPTIONS", "CAVE_PRINT_IDS_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
+ throw args::DoHelp("print-ids takes exactly one parameter");
+
+ const std::tr1::shared_ptr<const SetSpecTree> set(env->set(SetName(*cmdline.begin_parameters())));
+ if (! set)
+ throw NothingMatching(*cmdline.begin_parameters());
+
+ std::set<SetName> recursing;
+ set->root()->accept(SetPrinter(env, cmdline, recursing));
+
+ return EXIT_SUCCESS;
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+PrintSetCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new PrintSetCommandLine);
+}
+
diff --git a/src/clients/cave/cmd_print_set.hh b/src/clients/cave/cmd_print_set.hh
new file mode 100644
index 0000000..b0ef6ab
--- /dev/null
+++ b/src/clients/cave/cmd_print_set.hh
@@ -0,0 +1,43 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2010 Ciaran McCreesh
+ *
+ * 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_SET_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_SET_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE PrintSetCommand :
+ 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 2acb1ab..d013005 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -59,6 +59,7 @@
#include "cmd_print_packages.hh"
#include "cmd_print_repositories.hh"
#include "cmd_print_repository_formats.hh"
+#include "cmd_print_set.hh"
#include "cmd_print_sets.hh"
#include "cmd_print_sync_protocols.hh"
#include "cmd_purge.hh"
@@ -159,6 +160,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("print-packages", std::tr1::bind(&make_command<PrintPackagesCommand>)));
_imp->handlers.insert(std::make_pair("print-repositories", std::tr1::bind(&make_command<PrintRepositoriesCommand>)));
_imp->handlers.insert(std::make_pair("print-repository-formats", std::tr1::bind(&make_command<PrintRepositoryFormatsCommand>)));
+ _imp->handlers.insert(std::make_pair("print-set", std::tr1::bind(&make_command<PrintSetCommand>)));
_imp->handlers.insert(std::make_pair("print-sets", std::tr1::bind(&make_command<PrintSetsCommand>)));
_imp->handlers.insert(std::make_pair("print-sync-protocols", std::tr1::bind(&make_command<PrintSyncProtocolsCommand>)));
_imp->handlers.insert(std::make_pair("resolve", std::tr1::bind(&make_command<ResolveCommand>)));