aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-02-23 19:23:24 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-02-23 19:23:24 +0000
commit777d6d7695852b15c0a00bf4b8f9792ad7f6edc5 (patch)
tree48d8b613629cbb44d65f95c8bd339702b3fee943
parent929109c5ba9802d51752abd75ce6328afcfd9833 (diff)
downloadpaludis-777d6d7695852b15c0a00bf4b8f9792ad7f6edc5.tar.gz
paludis-777d6d7695852b15c0a00bf4b8f9792ad7f6edc5.tar.xz
cave config
-rw-r--r--src/clients/cave/Makefile.am3
-rw-r--r--src/clients/cave/cmd_config.cc121
-rw-r--r--src/clients/cave/cmd_config.hh43
-rw-r--r--src/clients/cave/command_factory.cc4
4 files changed, 169 insertions, 2 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index d427931..3447dc8 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -18,6 +18,7 @@ bin_PROGRAMS = cave
noinst_PROGRAMS = man-cave
command_MANS = \
+ cave-config.1 \
cave-display-resolution.1 \
cave-execute-resolution.1 \
cave-help.1 \
@@ -82,6 +83,7 @@ libcave_a_SOURCES = \
command_line.cc command_line.hh \
command_command_line.cc command_command_line.hh \
command_factory.cc command_factory.hh \
+ cmd_config.cc cmd_config.hh \
cmd_display_resolution.cc cmd_display_resolution.hh \
cmd_execute_resolution.cc cmd_execute_resolution.hh \
cmd_help.cc cmd_help.hh \
@@ -117,7 +119,6 @@ libcave_a_SOURCES = \
match_qpns.cc match_qpns.hh \
resolve_common.cc resolve_common.hh
-# cmd_config.cc \
# cmd_contents.cc \
# cmd_executables.cc \
# cmd_info.cc \
diff --git a/src/clients/cave/cmd_config.cc b/src/clients/cave/cmd_config.cc
new file mode 100644
index 0000000..82c9103
--- /dev/null
+++ b/src/clients/cave/cmd_config.cc
@@ -0,0 +1,121 @@
+/* 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_config.hh"
+#include "exceptions.hh"
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/make_named_values.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_database.hh>
+#include <paludis/repository.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/selection.hh>
+#include <paludis/package_id.hh>
+#include <paludis/action.hh>
+#include <paludis/hook.hh>
+#include <paludis/output_manager_from_environment.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 ConfigCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave config";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Perform post-install configuration on a package.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Perform post-install configuration on a package. Note that most packages do "
+ "not provide a post-install configuration script.";
+ }
+
+ ConfigCommandLine()
+ {
+ add_usage_line("spec");
+ }
+ };
+}
+
+int
+ConfigCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ ConfigCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_CONFIG_OPTIONS", "CAVE_CONFIG_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
+ throw args::DoHelp("config takes exactly one parameter");
+
+ PackageDepSpec spec(parse_user_package_dep_spec(*cmdline.begin_parameters(), env.get(),
+ UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsUnsorted(
+ generator::Matches(spec, MatchPackageOptions()) | filter::SupportsAction<ConfigAction>())]);
+ if (ids->empty())
+ throw NothingMatching(spec);
+ else if (1 != std::distance(ids->begin(), ids->end()))
+ throw BeMoreSpecific(spec, ids);
+ const std::tr1::shared_ptr<const PackageID> id(*ids->begin());
+
+ OutputManagerFromEnvironment output_manager_holder(env.get(), id, oe_exclusive, ClientOutputFeatures());
+ ConfigAction action(make_named_values<ConfigActionOptions>(
+ value_for<n::make_output_manager>(std::tr1::ref(output_manager_holder))
+ ));
+ id->perform_action(action);
+
+ return EXIT_SUCCESS;
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+ConfigCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new ConfigCommandLine);
+}
+
diff --git a/src/clients/cave/cmd_config.hh b/src/clients/cave/cmd_config.hh
new file mode 100644
index 0000000..22d41f0
--- /dev/null
+++ b/src/clients/cave/cmd_config.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_CONFIG_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_CONFIG_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE ConfigCommand :
+ 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 9ee1dea..e6a4e8b 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2008, 2009, 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
@@ -26,6 +26,7 @@
#include <tr1/functional>
#include <map>
+#include "cmd_config.hh"
#include "cmd_display_resolution.hh"
#include "cmd_execute_resolution.hh"
#include "cmd_help.hh"
@@ -81,6 +82,7 @@ namespace
CommandFactory::CommandFactory() :
PrivateImplementationPattern<CommandFactory>(new Implementation<CommandFactory>)
{
+ _imp->handlers.insert(std::make_pair("config", std::tr1::bind(&make_command<ConfigCommand>)));
_imp->handlers.insert(std::make_pair("display-resolution", std::tr1::bind(&make_command<DisplayResolutionCommand>)));
_imp->handlers.insert(std::make_pair("execute-resolution", std::tr1::bind(&make_command<ExecuteResolutionCommand>)));
_imp->handlers.insert(std::make_pair("help", std::tr1::bind(&make_command<HelpCommand>)));