aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-05 13:56:51 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-05 13:56:51 +0100
commit163289879e4df006071f23447eb08f81d0053452 (patch)
treef3ad02a16c79335472c5e5de2f44c9155e7d4299
parent42675b7064afee5ebb75b37a06b163ab65b04118 (diff)
downloadpaludis-163289879e4df006071f23447eb08f81d0053452.tar.gz
paludis-163289879e4df006071f23447eb08f81d0053452.tar.xz
cave contents
Fixes: ticket:826
-rw-r--r--src/clients/cave/Makefile.am3
-rw-r--r--src/clients/cave/cmd_contents.cc154
-rw-r--r--src/clients/cave/cmd_contents.hh44
-rw-r--r--src/clients/cave/command_factory.cc2
-rw-r--r--src/clients/cave/formats.cc25
-rw-r--r--src/clients/cave/formats.hh5
6 files changed, 232 insertions, 1 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 952c0b3..c38aa65 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -19,6 +19,7 @@ noinst_PROGRAMS = man-cave
command_MANS = \
cave-config.1 \
+ cave-contents.1 \
cave-display-resolution.1 \
cave-execute-resolution.1 \
cave-find-candidates.1 \
@@ -88,6 +89,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_contents.cc cmd_contents.hh \
cmd_config.cc cmd_config.hh \
cmd_display_resolution.cc cmd_display_resolution.hh \
cmd_execute_resolution.cc cmd_execute_resolution.hh \
@@ -131,7 +133,6 @@ libcave_a_SOURCES = \
match_qpns.cc match_qpns.hh \
resolve_common.cc resolve_common.hh
-# cmd_contents.cc \
# cmd_executables.cc \
# cmd_owner.cc \
# cmd_print_id_actions.cc \
diff --git a/src/clients/cave/cmd_contents.cc b/src/clients/cave/cmd_contents.cc
new file mode 100644
index 0000000..35a05d5
--- /dev/null
+++ b/src/clients/cave/cmd_contents.cc
@@ -0,0 +1,154 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * 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
+ * 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_contents.hh"
+#include "exceptions.hh"
+#include "formats.hh"
+#include "format_general.hh"
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/environment.hh>
+#include <paludis/contents.hh>
+#include <paludis/user_dep_spec.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 <paludis/util/stringify.hh>
+#include <paludis/filter.hh>
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
+#include <paludis/package_id.hh>
+#include <paludis/metadata_key.hh>
+#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 ContentsCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave contents";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Prints the contents of a package ID.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Display the contents of (files installed by) a given package ID.";
+ }
+
+ ContentsCommandLine()
+ {
+ add_usage_line("spec");
+ }
+ };
+
+ struct StringifyContentsEntry
+ {
+ std::string visit(const ContentsFileEntry & e) const
+ {
+ return format_general_s(f::contents_file(), stringify(e.location_key()->value()));
+ }
+
+ std::string visit(const ContentsDirEntry & e) const
+ {
+ return format_general_s(f::contents_dir(), stringify(e.location_key()->value()));
+ }
+
+ std::string visit(const ContentsSymEntry & e) const
+ {
+ return format_general_sr(f::contents_sym(), stringify(e.location_key()->value()),
+ stringify(e.target_key()->value()));
+ }
+
+ std::string visit(const ContentsOtherEntry & e) const
+ {
+ return format_general_s(f::contents_other(), stringify(e.location_key()->value()));
+ }
+ };
+
+ std::string stringify_contents_entry(const std::tr1::shared_ptr<const ContentsEntry> & e)
+ {
+ return e->accept_returning<std::string>(StringifyContentsEntry());
+ }
+}
+
+int
+ContentsCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ ContentsCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_CONTENTS_OPTIONS", "CAVE_CONTENTS_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
+ throw args::DoHelp("contents takes exactly one parameter");
+
+ PackageDepSpec spec(parse_user_package_dep_spec(*cmdline.begin_parameters(), env.get(),
+ UserPackageDepSpecOptions(), filter::InstalledAtRoot(env->root())));
+
+ std::tr1::shared_ptr<const PackageIDSequence> entries(
+ (*env)[selection::AllVersionsSorted(generator::Matches(spec, MatchPackageOptions()) | filter::InstalledAtRoot(env->root()))]);
+
+ if (entries->empty())
+ throw NothingMatching(spec);
+
+ const std::tr1::shared_ptr<const PackageID> id(*entries->last());
+ if (! id->contents_key())
+ throw BadIDForCommand(spec, id, "does not support listing contents");
+
+ std::transform(
+ id->contents_key()->value()->begin(),
+ id->contents_key()->value()->end(),
+ std::ostream_iterator<std::string>(cout, "\n"),
+ std::tr1::bind(stringify_contents_entry, std::tr1::placeholders::_1));
+
+ return EXIT_SUCCESS;
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+ContentsCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new ContentsCommandLine);
+}
+
diff --git a/src/clients/cave/cmd_contents.hh b/src/clients/cave/cmd_contents.hh
new file mode 100644
index 0000000..6093eaf
--- /dev/null
+++ b/src/clients/cave/cmd_contents.hh
@@ -0,0 +1,44 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008, 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_CONTENTS_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_CONTENTS_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE ContentsCommand :
+ 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 04ef390..20a8b7b 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -27,6 +27,7 @@
#include <map>
#include "cmd_config.hh"
+#include "cmd_contents.hh"
#include "cmd_display_resolution.hh"
#include "cmd_execute_resolution.hh"
#include "cmd_find_candidates.hh"
@@ -89,6 +90,7 @@ 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("contents", std::tr1::bind(&make_command<ContentsCommand>)));
_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("find-candidates", std::tr1::bind(&make_command<FindCandidatesCommand>)));
diff --git a/src/clients/cave/formats.cc b/src/clients/cave/formats.cc
index f029318..1984900 100644
--- a/src/clients/cave/formats.cc
+++ b/src/clients/cave/formats.cc
@@ -633,3 +633,28 @@ paludis::cave::f::sync_repo_tail()
return " ... %s\\n";
}
+const std::string
+paludis::cave::f::contents_file()
+{
+ return c::bold_blue_or_pink() + "%s" + c::normal();
+}
+
+const std::string
+paludis::cave::f::contents_dir()
+{
+ return c::blue_or_pink() + "%s" + c::normal();
+}
+
+const std::string
+paludis::cave::f::contents_sym()
+{
+ return c::bold_green_or_pink() + "%s" + c::normal() + " -> %r";
+}
+
+const std::string
+paludis::cave::f::contents_other()
+{
+ return c::bold_yellow() + "%s" + c::normal();
+}
+
+
diff --git a/src/clients/cave/formats.hh b/src/clients/cave/formats.hh
index 05bd498..60bb395 100644
--- a/src/clients/cave/formats.hh
+++ b/src/clients/cave/formats.hh
@@ -159,6 +159,11 @@ namespace paludis
const std::string sync_repo_active();
const std::string sync_repo_active_quiet();
const std::string sync_repo_tail();
+
+ const std::string contents_file();
+ const std::string contents_dir();
+ const std::string contents_sym();
+ const std::string contents_other();
}
}
}