aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-15 23:34:59 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-15 23:34:59 +0100
commit4223aeac6757f1b34f69e78a292747f14fb97140 (patch)
tree7190c7d3d905bcbb74b57aae658ee76b45e94fd6
parent84ace8b4ae6078d40c95fe1b5ad25fbec34e96fd (diff)
downloadpaludis-4223aeac6757f1b34f69e78a292747f14fb97140.tar.gz
paludis-4223aeac6757f1b34f69e78a292747f14fb97140.tar.xz
cave update-world
-rw-r--r--src/clients/cave/Makefile.am1
-rw-r--r--src/clients/cave/cmd_update_world.cc129
-rw-r--r--src/clients/cave/cmd_update_world.hh43
-rw-r--r--src/clients/cave/command_factory.cc2
4 files changed, 175 insertions, 0 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index d2634e8..c115cf5 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -97,6 +97,7 @@ libcave_a_SOURCES = \
cmd_resolve_dump.cc cmd_resolve_dump.hh \
cmd_show.cc cmd_show.hh \
cmd_sync.cc cmd_sync.hh \
+ cmd_update_world.cc cmd_update_world.hh \
exceptions.cc exceptions.hh \
format_general.cc format_general.hh \
format_plain_contents_entry.cc format_plain_contents_entry.hh \
diff --git a/src/clients/cave/cmd_update_world.cc b/src/clients/cave/cmd_update_world.cc
new file mode 100644
index 0000000..b53e669
--- /dev/null
+++ b/src/clients/cave/cmd_update_world.cc
@@ -0,0 +1,129 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 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_update_world.hh"
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_database.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/iterator_funcs.hh>
+#include <paludis/util/options.hh>
+#include <paludis/util/sequence.hh>
+#include <iostream>
+
+#include "command_command_line.hh"
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct UpdateWorldCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave update-world";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Updates the world set.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Adds or removes items from the world set.";
+ }
+
+ args::ArgsGroup g_update_options;
+ args::SwitchArg a_remove;
+ args::SwitchArg a_set;
+
+ UpdateWorldCommandLine() :
+ g_update_options(this, "Update Options", "Alter how updates are performed."),
+ a_remove(&g_update_options, "remove", 'r', "Remove the specified items instead of adding them", true),
+ a_set(&g_update_options, "set", 's', "The parameters are set names, not package names", true)
+ {
+ add_usage_line("[ --remove ] cat/pkg ...");
+ add_usage_line("[ --remove ] --set setname ...");
+ }
+ };
+}
+
+int
+UpdateWorldCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ UpdateWorldCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_UPDATE_WORLD_OPTIONS", "CAVE_UPDATE_WORLD_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (cmdline.begin_parameters() == cmdline.end_parameters())
+ throw args::DoHelp("update-world requires at least one parameter");
+
+ for (UpdateWorldCommandLine::ParametersConstIterator p(cmdline.begin_parameters()),
+ p_end(cmdline.end_parameters()) ;
+ p != p_end ; ++p)
+ {
+ if (cmdline.a_set.specified())
+ {
+ if (cmdline.a_remove.specified())
+ env->remove_from_world(SetName(*p));
+ else
+ env->add_to_world(SetName(*p));
+ }
+ else
+ {
+ QualifiedPackageName q("x/x");
+
+ if (std::string::npos == p->find('/'))
+ q = env->package_database()->fetch_unique_qualified_package_name(PackageNamePart(*p));
+ else
+ q = QualifiedPackageName(*p);
+
+ if (cmdline.a_remove.specified())
+ env->remove_from_world(q);
+ else
+ env->add_to_world(q);
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+UpdateWorldCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new UpdateWorldCommandLine);
+}
+
+
diff --git a/src/clients/cave/cmd_update_world.hh b/src/clients/cave/cmd_update_world.hh
new file mode 100644
index 0000000..7874fdb
--- /dev/null
+++ b/src/clients/cave/cmd_update_world.hh
@@ -0,0 +1,43 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 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_UPDATE_WORLD_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_UPDATE_WORLD_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE UpdateWorldCommand :
+ 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 c07df95..0eee7a7 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -43,6 +43,7 @@
#include "cmd_resolve.hh"
#include "cmd_show.hh"
#include "cmd_sync.hh"
+#include "cmd_update_world.hh"
using namespace paludis;
using namespace cave;
@@ -87,6 +88,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("resolve", make_command<ResolveCommand>));
_imp->handlers.insert(std::make_pair("show", make_command<ShowCommand>));
_imp->handlers.insert(std::make_pair("sync", make_command<SyncCommand>));
+ _imp->handlers.insert(std::make_pair("update-world", make_command<UpdateWorldCommand>));
}
CommandFactory::~CommandFactory()