aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-10-29 19:38:07 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-10-29 19:38:07 +0100
commit0eca1782c210b2c9bb736502a6763cf4f559f959 (patch)
tree3f76b3d7aa119338a01037d5337d7707ee5c939a
parenta163c1907f9a7fd6b8c0e243b335247b8bde7e46 (diff)
downloadpaludis-0eca1782c210b2c9bb736502a6763cf4f559f959.tar.gz
paludis-0eca1782c210b2c9bb736502a6763cf4f559f959.tar.xz
cave has-version, print-best-version
Fixes: ticket:1027
-rw-r--r--.gitignore2
-rw-r--r--doc/clients/Makefile.am2
-rw-r--r--src/clients/cave/Makefile.am4
-rw-r--r--src/clients/cave/cmd_has_version.cc113
-rw-r--r--src/clients/cave/cmd_has_version.hh44
-rw-r--r--src/clients/cave/cmd_print_best_version.cc142
-rw-r--r--src/clients/cave/cmd_print_best_version.hh44
-rw-r--r--src/clients/cave/command_factory.cc4
8 files changed, 355 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index ca61a57..c4779d1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -91,6 +91,7 @@ paludis-*.*.*.tar.bz2
/doc/clients/cave-fix-cache.html
/doc/clients/cave-fix-linkage.html
/doc/clients/cave-graph-jobs.html
+/doc/clients/cave-has-version.html
/doc/clients/cave-help.html
/doc/clients/cave-import.html
/doc/clients/cave-info.html
@@ -98,6 +99,7 @@ paludis-*.*.*.tar.bz2
/doc/clients/cave-match.html
/doc/clients/cave-owner.html
/doc/clients/cave-perform.html
+/doc/clients/cave-print-best-version.html
/doc/clients/cave-print-categories.html
/doc/clients/cave-print-commands.html
/doc/clients/cave-print-environment-metadata.html
diff --git a/doc/clients/Makefile.am b/doc/clients/Makefile.am
index 2a33cf3..2d713f6 100644
--- a/doc/clients/Makefile.am
+++ b/doc/clients/Makefile.am
@@ -36,6 +36,7 @@ CAVE_COMMANDS_HTML = \
cave-fix-cache.html \
cave-fix-linkage.html \
cave-graph-jobs.html \
+ cave-has-version.html \
cave-help.html \
cave-import.html \
cave-info.html \
@@ -43,6 +44,7 @@ CAVE_COMMANDS_HTML = \
cave-match.html \
cave-owner.html \
cave-perform.html \
+ cave-print-best-version.html \
cave-print-categories.html \
cave-print-commands.html \
cave-print-environment-metadata.html \
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 02cbed7..b6677a5 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -32,6 +32,7 @@ command_MANS = \
cave-fix-cache.1 \
cave-fix-linkage.1 \
cave-graph-jobs.1 \
+ cave-has-version.1 \
cave-help.1 \
cave-import.1 \
cave-info.1 \
@@ -39,6 +40,7 @@ command_MANS = \
cave-match.1 \
cave-owner.1 \
cave-perform.1 \
+ cave-print-best-version.1 \
cave-print-categories.1 \
cave-print-commands.1 \
cave-print-environment-metadata.1 \
@@ -129,6 +131,7 @@ libcave_a_SOURCES = \
cmd_fix_cache.cc cmd_fix_cache.hh cmd_fix_cache-fmt.hh \
cmd_fix_linkage.cc cmd_fix_linkage.hh \
cmd_graph_jobs.cc cmd_graph_jobs.hh \
+ cmd_has_version.cc cmd_has_version.hh \
cmd_help.cc cmd_help.hh \
cmd_import.cc cmd_import.hh \
cmd_info.cc cmd_info.hh cmd_info-fmt.hh \
@@ -136,6 +139,7 @@ libcave_a_SOURCES = \
cmd_match.cc cmd_match.hh \
cmd_owner.cc cmd_owner.hh cmd_owner-fmt.hh \
cmd_perform.cc cmd_perform.hh cmd_perform-fmt.hh \
+ cmd_print_best_version.cc cmd_print_best_version.hh \
cmd_print_categories.cc cmd_print_categories.hh \
cmd_print_commands.cc cmd_print_commands.hh \
cmd_print_environment_metadata.cc cmd_print_environment_metadata.hh \
diff --git a/src/clients/cave/cmd_has_version.cc b/src/clients/cave/cmd_has_version.cc
new file mode 100644
index 0000000..3015fcb
--- /dev/null
+++ b/src/clients/cave/cmd_has_version.cc
@@ -0,0 +1,113 @@
+/* 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_has_version.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/util/set.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/simple_visitor_cast.hh>
+#include <paludis/util/map.hh>
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filter_handler.hh>
+#include <paludis/selection.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/package_id.hh>
+#include <paludis/mask.hh>
+#include <paludis/metadata_key.hh>
+#include <cstdlib>
+#include <iostream>
+#include <algorithm>
+
+#include "command_command_line.hh"
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct HasVersionCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave has-version";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Returns success if there is an installed package matching a particular spec.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Returns success if there is an installed package matching a particular spec. Suitable "
+ "for use in scripts.";
+ }
+
+ HasVersionCommandLine()
+ {
+ add_usage_line("spec");
+ }
+ };
+}
+
+int
+HasVersionCommand::run(
+ const std::shared_ptr<Environment> & env,
+ const std::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ HasVersionCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_HAS_VERSION_OPTIONS", "CAVE_HAS_VERSION_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
+ throw args::DoHelp("has-version takes exactly one parameter");
+
+ auto s(parse_user_package_dep_spec(*cmdline.begin_parameters(), env.get(), { }));
+ auto ids((*env)[selection::BestVersionOnly(generator::Matches(s, { }) | filter::InstalledAtRoot(
+ env->preferred_root_key()->value()))]);
+
+ if (ids->empty())
+ return EXIT_FAILURE;
+ else
+ return EXIT_SUCCESS;
+}
+
+std::shared_ptr<args::ArgsHandler>
+HasVersionCommand::make_doc_cmdline()
+{
+ return std::make_shared<HasVersionCommandLine>();
+}
+
diff --git a/src/clients/cave/cmd_has_version.hh b/src/clients/cave/cmd_has_version.hh
new file mode 100644
index 0000000..59be998
--- /dev/null
+++ b/src/clients/cave/cmd_has_version.hh
@@ -0,0 +1,44 @@
+/* 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_HAS_VERSION_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_HAS_VERSION_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE HasVersionCommand :
+ public Command
+ {
+ public:
+ int run(
+ const std::shared_ptr<Environment> &,
+ const std::shared_ptr<const Sequence<std::string > > & args
+ );
+
+ std::shared_ptr<args::ArgsHandler> make_doc_cmdline();
+ };
+ }
+}
+
+
+#endif
diff --git a/src/clients/cave/cmd_print_best_version.cc b/src/clients/cave/cmd_print_best_version.cc
new file mode 100644
index 0000000..5059ebf
--- /dev/null
+++ b/src/clients/cave/cmd_print_best_version.cc
@@ -0,0 +1,142 @@
+/* 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_best_version.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/util/set.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/simple_visitor_cast.hh>
+#include <paludis/util/map.hh>
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filter_handler.hh>
+#include <paludis/selection.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/package_id.hh>
+#include <paludis/mask.hh>
+#include <paludis/metadata_key.hh>
+#include <cstdlib>
+#include <iostream>
+#include <algorithm>
+
+#include "command_command_line.hh"
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct PrintBestVersionCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave print-best-version";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Prints the best installed version matching a particular spec.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Prints the best installed version matching a particular spec. No "
+ "formatting is used, making the output suitable for parsing by scripts.";
+ }
+
+ args::ArgsGroup g_display_options;
+ args::EnumArg a_format;
+
+ PrintBestVersionCommandLine() :
+ g_display_options(main_options_section(), "Display Options", "Controls the output format."),
+ a_format(&g_display_options, "format", 'f', "Select the output format.",
+ args::EnumArg::EnumArgOptions
+ ("full", 'f', "Display the full canonical representation")
+ ("spec", 's', "Display the ID as a uniquely identifying spec")
+ ("name", 'n', "Display only the name")
+ ("version", 'v', "Display only the version")
+ ("name-version", 'V', "Display the name and the version"),
+ "full")
+ {
+ add_usage_line("spec");
+ }
+ };
+}
+
+int
+PrintBestVersionCommand::run(
+ const std::shared_ptr<Environment> & env,
+ const std::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ PrintBestVersionCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_BEST_VERSION_OPTIONS", "CAVE_BEST_VERSION_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-best-version takes exactly one parameter");
+
+ auto s(parse_user_package_dep_spec(*cmdline.begin_parameters(), env.get(), { }));
+ auto ids((*env)[selection::BestVersionOnly(generator::Matches(s, { }) | filter::InstalledAtRoot(
+ env->preferred_root_key()->value()))]);
+
+ if (ids->empty())
+ return EXIT_FAILURE;
+ else
+ {
+ auto id(*ids->begin());
+ if (cmdline.a_format.argument() == "full")
+ cout << id->canonical_form(idcf_full);
+ else if (cmdline.a_format.argument() == "spec")
+ cout << id->uniquely_identifying_spec();
+ else if (cmdline.a_format.argument() == "name")
+ cout << id->name();
+ else if (cmdline.a_format.argument() == "version")
+ cout << id->version();
+ else if (cmdline.a_format.argument() == "name-version")
+ cout << id->name() << "-" << id->version();
+ else
+ throw args::DoHelp("bad value '" + cmdline.a_format.argument() + "' for --" + cmdline.a_format.long_name());
+ cout << endl;
+
+ return EXIT_SUCCESS;
+ }
+}
+
+std::shared_ptr<args::ArgsHandler>
+PrintBestVersionCommand::make_doc_cmdline()
+{
+ return std::make_shared<PrintBestVersionCommandLine>();
+}
+
diff --git a/src/clients/cave/cmd_print_best_version.hh b/src/clients/cave/cmd_print_best_version.hh
new file mode 100644
index 0000000..913a0f5
--- /dev/null
+++ b/src/clients/cave/cmd_print_best_version.hh
@@ -0,0 +1,44 @@
+/* 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_BEST_VERSION_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_BEST_VERSION_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE PrintBestVersionCommand :
+ public Command
+ {
+ public:
+ int run(
+ const std::shared_ptr<Environment> &,
+ const std::shared_ptr<const Sequence<std::string > > & args
+ );
+
+ std::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 6974c9e..c1b79c1 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -45,6 +45,7 @@
#include "cmd_fix_cache.hh"
#include "cmd_fix_linkage.hh"
#include "cmd_graph_jobs.hh"
+#include "cmd_has_version.hh"
#include "cmd_help.hh"
#include "cmd_import.hh"
#include "cmd_info.hh"
@@ -52,6 +53,7 @@
#include "cmd_match.hh"
#include "cmd_owner.hh"
#include "cmd_perform.hh"
+#include "cmd_print_best_version.hh"
#include "cmd_print_categories.hh"
#include "cmd_print_commands.hh"
#include "cmd_print_environment_metadata.hh"
@@ -158,6 +160,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("fix-cache", std::bind(&make_command<FixCacheCommand>)));
_imp->handlers.insert(std::make_pair("fix-linkage", std::bind(&make_command<FixLinkageCommand>)));
_imp->handlers.insert(std::make_pair("graph-jobs", std::bind(&make_command<GraphJobsCommand>)));
+ _imp->handlers.insert(std::make_pair("has-version", std::bind(&make_command<HasVersionCommand>)));
_imp->handlers.insert(std::make_pair("help", std::bind(&make_command<HelpCommand>)));
_imp->handlers.insert(std::make_pair("import", std::bind(&make_command<ImportCommand>)));
_imp->handlers.insert(std::make_pair("info", std::bind(&make_command<InfoCommand>)));
@@ -166,6 +169,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("owner", std::bind(&make_command<OwnerCommand>)));
_imp->handlers.insert(std::make_pair("perform", std::bind(&make_command<PerformCommand>)));
_imp->handlers.insert(std::make_pair("purge", std::bind(&make_command<PurgeCommand>)));
+ _imp->handlers.insert(std::make_pair("print-best-version", std::bind(&make_command<PrintBestVersionCommand>)));
_imp->handlers.insert(std::make_pair("print-categories", std::bind(&make_command<PrintCategoriesCommand>)));
_imp->handlers.insert(std::make_pair("print-commands", std::bind(&make_command<PrintCommandsCommand>)));
_imp->handlers.insert(std::make_pair("print-environment-metadata", std::bind(&make_command<PrintEnvironmentMetadataCommand>)));