aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-16 20:37:28 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-16 21:15:08 +0100
commitfa6863d997543b56f0911194187cfbe965acbce6 (patch)
tree9421678afbb426aa3333feb114fc46176d5d484e
parent2a49ae23c623e5aad14d9d46d7a109fd38e3e181 (diff)
downloadpaludis-fa6863d997543b56f0911194187cfbe965acbce6.tar.gz
paludis-fa6863d997543b56f0911194187cfbe965acbce6.tar.xz
cave print-formats
-rw-r--r--.gitignore1
-rw-r--r--doc/clients/Makefile.am1
-rw-r--r--src/clients/cave/Makefile.am2
-rw-r--r--src/clients/cave/cmd_print_formats.cc204
-rw-r--r--src/clients/cave/cmd_print_formats.hh43
-rw-r--r--src/clients/cave/command_factory.cc2
6 files changed, 253 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e96286b..7c93ae1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -99,6 +99,7 @@ paludis-*.*.*.tar.bz2
/doc/clients/cave-print-categories.html
/doc/clients/cave-print-commands.html
/doc/clients/cave-print-environment-metadata.html
+/doc/clients/cave-print-formats.html
/doc/clients/cave-print-id-actions.html
/doc/clients/cave-print-id-contents.html
/doc/clients/cave-print-id-environment-variable.html
diff --git a/doc/clients/Makefile.am b/doc/clients/Makefile.am
index 2fbbd25..0527590 100644
--- a/doc/clients/Makefile.am
+++ b/doc/clients/Makefile.am
@@ -44,6 +44,7 @@ CAVE_COMMANDS_HTML = \
cave-print-categories.html \
cave-print-commands.html \
cave-print-environment-metadata.html \
+ cave-print-formats.html \
cave-print-id-actions.html \
cave-print-id-contents.html \
cave-print-id-environment-variable.html \
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 70ff463..a608e9c 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -37,6 +37,7 @@ command_MANS = \
cave-print-categories.1 \
cave-print-commands.1 \
cave-print-environment-metadata.1 \
+ cave-print-formats.1 \
cave-print-id-actions.1 \
cave-print-id-contents.1 \
cave-print-id-environment-variable.1 \
@@ -128,6 +129,7 @@ libcave_a_SOURCES = \
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 \
+ cmd_print_formats.cc cmd_print_formats.hh \
cmd_print_id_actions.cc cmd_print_id_actions.hh \
cmd_print_id_contents.cc cmd_print_id_contents.hh \
cmd_print_id_environment_variable.cc cmd_print_id_environment_variable.hh \
diff --git a/src/clients/cave/cmd_print_formats.cc b/src/clients/cave/cmd_print_formats.cc
new file mode 100644
index 0000000..71945d7
--- /dev/null
+++ b/src/clients/cave/cmd_print_formats.cc
@@ -0,0 +1,204 @@
+/* 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_formats.hh"
+#include <paludis/util/stringify.hh>
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <cstdlib>
+#include <iostream>
+#include <algorithm>
+#include <map>
+
+#include "command_command_line.hh"
+
+#include "config.h"
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ namespace c
+ {
+ const std::string red() { return "${red}"; }
+ const std::string bold_red() { return "${bold_red}"; }
+ const std::string green() { return "${green}"; }
+ const std::string bold_green() { return "${bold_green}"; }
+ const std::string yellow() { return "${yellow}"; }
+ const std::string bold_yellow() { return "${bold_yellow}"; }
+ const std::string blue() { return "${blue}"; }
+ const std::string bold_blue() { return "${bold_blue}"; }
+ const std::string pink() { return "${pink}"; }
+ const std::string bold_pink() { return "${bold_pink}"; }
+ const std::string normal() { return "${normal}"; }
+ const std::string bold_normal() { return "${bold_normal}"; }
+
+#if PALUDIS_COLOUR_PINK
+ const std::string blue_or_pink() { return pink(); }
+ const std::string bold_blue_or_pink() { return bold_pink(); }
+ const std::string green_or_pink() { return pink(); }
+ const std::string bold_green_or_pink() { return bold_pink(); }
+#else
+ const std::string blue_or_pink() { return blue(); }
+ const std::string bold_blue_or_pink() { return bold_blue(); }
+ const std::string green_or_pink() { return green(); }
+ const std::string bold_green_or_pink() { return bold_green(); }
+#endif
+ }
+
+ template <char c_>
+ std::string param()
+ {
+ return "%" + std::string(1, c_);
+ }
+
+ struct Storer
+ {
+ std::string user_key;
+ int user_key_version;
+
+ std::string value;
+ };
+
+ Storer && operator<< (Storer && s, const std::string & t)
+ {
+ s.value.append(t);
+ return s;
+ }
+
+ struct GetFormats
+ {
+ std::map<std::string, Storer> storers;
+
+ Storer & make_format_string_fetcher(const std::string & v, const int vi)
+ {
+ std::string k(0 == vi ? v : v + "." + stringify(vi));
+ auto i(storers.insert(std::make_pair(k, Storer{v, vi, ""})));
+ if (! i.second)
+ throw InternalError(PALUDIS_HERE, "couldn't insert " + k);
+
+ return i.first->second;
+ }
+
+ void collect()
+ {
+
+#include "cmd_contents-fmt.hh"
+#include "cmd_verify-fmt.hh"
+
+ }
+ };
+}
+
+namespace
+{
+ struct PrintFormatsCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave print-formats";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Prints a list of known format strings.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Prints a list of known format strings. No formatting is used, making the output "
+ "suitable for parsing by scripts.";
+ }
+
+ PrintFormatsCommandLine()
+ {
+ add_usage_line("");
+ }
+ };
+}
+
+int
+PrintFormatsCommand::run(
+ const std::shared_ptr<Environment> &,
+ const std::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ PrintFormatsCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_PRINT_FORMATS_OPTIONS", "CAVE_PRINT_FORMATS_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (cmdline.begin_parameters() != cmdline.end_parameters())
+ throw args::DoHelp("print-formats takes no parameters");
+
+ cout << "[colours]" << endl;
+ cout << "red" << " = " << "\\e[0;31m" << endl;
+ cout << "bold_red" << " = " << "\\e[1;31m" << endl;
+ cout << "green" << " = " << "\\e[0;32m" << endl;
+ cout << "bold_green" << " = " << "\\e[1;32m" << endl;
+ cout << "yellow" << " = " << "\\e[0;33m" << endl;
+ cout << "bold_yellow" << " = " << "\\e[1;33m" << endl;
+ cout << "blue" << " = " << "\\e[0;34m" << endl;
+ cout << "bold_blue" << " = " << "\\e[1;34m" << endl;
+ cout << "pink" << " = " << "\\e[0;35m" << endl;
+ cout << "bold_pink" << " = " << "\\e[1;35m" << endl;
+ cout << "normal" << " = " << "\\e[0;0m" << endl;
+ cout << "bold_normal" << " = " << "\\e[1m" << endl;
+
+ GetFormats get_formats;
+ get_formats.collect();
+
+ std::string current_section;
+ for (auto i(get_formats.storers.begin()), i_end(get_formats.storers.end()) ;
+ i != i_end ; ++i)
+ {
+ std::string::size_type p(i->first.find("/"));
+ if (std::string::npos == p)
+ throw InternalError(PALUDIS_HERE, "weird key " + i->first);
+ std::string section(i->first.substr(0, p)), key(i->first.substr(p + 1));
+
+ if (current_section != section)
+ {
+ cout << endl << "[" << section << "]" << endl;
+ current_section = section;
+ }
+
+ cout << key << " = ";
+ if (0 == i->second.value.compare(0, 1, " "))
+ cout << "\\";
+ cout << i->second.value << endl;
+ }
+
+ return EXIT_SUCCESS;
+}
+
+std::shared_ptr<args::ArgsHandler>
+PrintFormatsCommand::make_doc_cmdline()
+{
+ return std::make_shared<PrintFormatsCommandLine>();
+}
+
diff --git a/src/clients/cave/cmd_print_formats.hh b/src/clients/cave/cmd_print_formats.hh
new file mode 100644
index 0000000..161947c
--- /dev/null
+++ b/src/clients/cave/cmd_print_formats.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_PRINT_FORMATS_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_FORMATS_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE PrintFormatsCommand :
+ 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 66d9355..4761186 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -51,6 +51,7 @@
#include "cmd_print_categories.hh"
#include "cmd_print_commands.hh"
#include "cmd_print_environment_metadata.hh"
+#include "cmd_print_formats.hh"
#include "cmd_print_id_actions.hh"
#include "cmd_print_id_contents.hh"
#include "cmd_print_id_environment_variable.hh"
@@ -159,6 +160,7 @@ CommandFactory::CommandFactory() :
_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>)));
+ _imp->handlers.insert(std::make_pair("print-formats", std::bind(&make_command<PrintFormatsCommand>)));
_imp->handlers.insert(std::make_pair("print-id-actions", std::bind(&make_command<PrintIDActionsCommand>)));
_imp->handlers.insert(std::make_pair("print-id-contents", std::bind(&make_command<PrintIDContentsCommand>)));
_imp->handlers.insert(std::make_pair("print-id-environment-variable", std::bind(&make_command<PrintIDEnvironmentVariableCommand>)));