diff options
author | 2012-03-30 19:12:45 +0100 | |
---|---|---|
committer | 2012-03-30 19:12:45 +0100 | |
commit | fa007bfd4ed95b28ea4a56621b7645212aa2ea39 (patch) | |
tree | fd1b46b780e0c4c47601ab4eaa03216137dd752f | |
parent | d5b8921e7a707d74e795b9549d1e07eb4973de9d (diff) | |
download | paludis-fa007bfd4ed95b28ea4a56621b7645212aa2ea39.tar.gz paludis-fa007bfd4ed95b28ea4a56621b7645212aa2ea39.tar.xz |
Add cave-print-checksum-algorithms
-rw-r--r-- | src/clients/cave/Makefile.am | 2 | ||||
-rw-r--r-- | src/clients/cave/cmd_print_checksum.cc | 1 | ||||
-rw-r--r-- | src/clients/cave/cmd_print_checksum_algorithms.cc | 94 | ||||
-rw-r--r-- | src/clients/cave/cmd_print_checksum_algorithms.hh | 43 | ||||
-rw-r--r-- | src/clients/cave/command_factory.cc | 2 |
5 files changed, 142 insertions, 0 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am index 62cce44ce..c8a30b2bd 100644 --- a/src/clients/cave/Makefile.am +++ b/src/clients/cave/Makefile.am @@ -44,6 +44,7 @@ command_MANS = \ cave-print-best-version.1 \ cave-print-categories.1 \ cave-print-checksum.1 \ + cave-print-checksum-algorithms.1 \ cave-print-commands.1 \ cave-print-dependent-ids.1 \ cave-print-environment-metadata.1 \ @@ -175,6 +176,7 @@ libcave_a_SOURCES = \ cmd_print_best_version.cc cmd_print_best_version.hh \ cmd_print_categories.cc cmd_print_categories.hh \ cmd_print_checksum.cc cmd_print_checksum.hh \ + cmd_print_checksum_algorithms.cc cmd_print_checksum_algorithms.hh \ cmd_print_commands.cc cmd_print_commands.hh \ cmd_print_dependent_ids.cc cmd_print_dependent_ids.hh \ cmd_print_environment_metadata.cc cmd_print_environment_metadata.hh \ diff --git a/src/clients/cave/cmd_print_checksum.cc b/src/clients/cave/cmd_print_checksum.cc index 7210c678d..c22624361 100644 --- a/src/clients/cave/cmd_print_checksum.cc +++ b/src/clients/cave/cmd_print_checksum.cc @@ -53,6 +53,7 @@ namespace add_usage_line("ALGORITHM --stdin"); add_usage_line("ALGORITHM --file FILENAME"); add_usage_line("ALGORITHM --text TEXT"); + add_see_also("cave-print-checksum-algorithms", 1); } virtual std::string app_name() const diff --git a/src/clients/cave/cmd_print_checksum_algorithms.cc b/src/clients/cave/cmd_print_checksum_algorithms.cc new file mode 100644 index 000000000..03ebbd865 --- /dev/null +++ b/src/clients/cave/cmd_print_checksum_algorithms.cc @@ -0,0 +1,94 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2012 David Leverton + * + * 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_checksum_algorithms.hh" +#include "command_command_line.hh" + +#include <paludis/util/digest_registry.hh> + +#include <paludis/args/do_help.hh> + +#include <iostream> + +using namespace paludis; +using namespace paludis::cave; + +namespace +{ + struct PrintChecksumAlgorithmsCommandLine : + CaveCommandCommandLine + { + PrintChecksumAlgorithmsCommandLine() + { + add_usage_line(""); + add_see_also("cave-print-checksum", 1); + } + + virtual std::string app_name() const + { + return "cave print-checksum-algorithms"; + } + + virtual std::string app_synopsis() const + { + return "prints supported cryptographic checksum algorithms"; + } + + virtual std::string app_description() const + { + return "Prints a list of supported checksum algorithms. No formatting " + "is used, making the output suitable for parsing by scripts."; + } + }; +} + +int +PrintChecksumAlgorithmsCommand::run(const std::shared_ptr<Environment> &, + const std::shared_ptr<const Sequence<std::string> > & args) +{ + PrintChecksumAlgorithmsCommandLine cmdline; + cmdline.run(args, "CAVE", "CAVE_PRINT_CHECKSUM_ALGORITHMS_OPTIONS", "CAVE_PRINT_CHECKSUM_ALGORITHMS_CMDLINE"); + + if (cmdline.a_help.specified()) + { + std::cout << cmdline; + return EXIT_SUCCESS; + } + + if (std::distance(cmdline.begin_parameters(), cmdline.end_parameters()) != 0) + throw args::DoHelp("print-checksum-algorithms takes no parameters"); + + auto reg(DigestRegistry::get_instance()); + for (auto it(reg->begin_algorithms()), it_end(reg->end_algorithms()); it_end != it; ++it) + std::cout << it->first << std::endl; + return EXIT_SUCCESS; +} + +std::shared_ptr<args::ArgsHandler> +PrintChecksumAlgorithmsCommand::make_doc_cmdline() +{ + return std::make_shared<PrintChecksumAlgorithmsCommandLine>(); +} + +CommandImportance +PrintChecksumAlgorithmsCommand::importance() const +{ + return ci_scripting; +} + diff --git a/src/clients/cave/cmd_print_checksum_algorithms.hh b/src/clients/cave/cmd_print_checksum_algorithms.hh new file mode 100644 index 000000000..2c1105623 --- /dev/null +++ b/src/clients/cave/cmd_print_checksum_algorithms.hh @@ -0,0 +1,43 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2012 David Leverton + * + * 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_CHECKSUM_ALGORITHMS_HH +#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_CHECKSUM_ALGORITHMS_HH 1 + +#include "command.hh" + +namespace paludis +{ + namespace cave + { + class PALUDIS_VISIBLE PrintChecksumAlgorithmsCommand : + public Command + { + public: + virtual CommandImportance importance() const PALUDIS_ATTRIBUTE((warn_unused_result)); + + 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 d08d67965..b373b1a2d 100644 --- a/src/clients/cave/command_factory.cc +++ b/src/clients/cave/command_factory.cc @@ -59,6 +59,7 @@ #include "cmd_print_best_version.hh" #include "cmd_print_categories.hh" #include "cmd_print_checksum.hh" +#include "cmd_print_checksum_algorithms.hh" #include "cmd_print_commands.hh" #include "cmd_print_dependent_ids.hh" #include "cmd_print_environment_metadata.hh" @@ -181,6 +182,7 @@ CommandFactory::CommandFactory() : _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-checksum", std::bind(&make_command<PrintChecksumCommand>))); + _imp->handlers.insert(std::make_pair("print-checksum-algorithms", std::bind(&make_command<PrintChecksumAlgorithmsCommand>))); _imp->handlers.insert(std::make_pair("print-commands", std::bind(&make_command<PrintCommandsCommand>))); _imp->handlers.insert(std::make_pair("print-dependent-ids", std::bind(&make_command<PrintDependentIDsCommand>))); _imp->handlers.insert(std::make_pair("print-environment-metadata", std::bind(&make_command<PrintEnvironmentMetadataCommand>))); |