From ca486d25b808931f7fb53873938fdb0a10c4bbf2 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 2 Apr 2016 15:30:16 -0400 Subject: [PATCH] CLI: Added ::dump --- src/CLI.cpp | 30 ++++++++++++++++++++++++++++++ src/CLI.h | 1 + 2 files changed, 31 insertions(+) diff --git a/src/CLI.cpp b/src/CLI.cpp index a1cc1575..205258ec 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include //////////////////////////////////////////////////////////////////////////////// @@ -158,3 +159,32 @@ bool CLI::canonicalize ( } //////////////////////////////////////////////////////////////////////////////// +const std::string CLI::dump (const std::string& title) const +{ + std::stringstream out; + + out << "\033[1m" << title << "\033[0m\n" + << " _original_args\n "; + + Color colorArgs ("gray10 on gray4"); + for (auto i = _original_args.begin (); i != _original_args.end (); ++i) + { + if (i != _original_args.begin ()) + out << ' '; + + out << colorArgs.colorize (i->attribute ("raw")); + } + + out << "\n"; + + if (_args.size ()) + { + out << " _args\n"; + for (const auto& a : _args) + out << " " << a.dump () << "\n"; + } + + return out.str (); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/CLI.h b/src/CLI.h index c305f5ff..53db05af 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -58,6 +58,7 @@ public: void entity (const std::string&, const std::string&); void add (const std::string&); bool canonicalize (std::string&, const std::string&, const std::string&) const; + const std::string dump (const std::string& title = "CLI Parser") const; public: std::multimap _entities {};