diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 6fc68bf2..c0ca647a 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -23,6 +23,7 @@ set (commands_SRCS CmdCancel.cpp CmdStart.cpp CmdStop.cpp CmdReportSummary.cpp + CmdShow.cpp CmdTags.cpp CmdTrack.cpp CmdUndo.cpp) diff --git a/src/commands/CmdShow.cpp b/src/commands/CmdShow.cpp new file mode 100644 index 00000000..e4a5abf0 --- /dev/null +++ b/src/commands/CmdShow.cpp @@ -0,0 +1,87 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2015 - 2016, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +//////////////////////////////////////////////////////////////////////////////// +int CmdShow (Rules& rules) +{ + // Obtain and sort the names. Sorting is critical. + auto names = rules.all (); + std::sort (names.begin (), names.end ()); + + std::vector previous {}; + for (auto& name : rules.all ()) + { + if (name.substr (0, 5) == "temp.") + continue; + + auto parts = split (name, '.'); + for (unsigned int i = 0; i < parts.size (); ++i) + { + // The last part is special. + if (i == parts.size () - 1) + { + if (previous.size () > 1 && + parts.size () == 1) + std::cout << '\n'; + + std::cout << std::string (2 * (parts.size () - 1), ' ') + << parts[i] + << " = " + << rules.get (name) + << "\n"; + } + else + { + if (previous.size () <= i || + previous[i] != parts[i]) + { + if (i == 0) + { + std::cout << '\n'; + if (rules.isRuleType (parts[0])) + std::cout << "define "; + } + + std::cout << std::string (2 * i, ' ') + << parts[i] + << ":\n"; + } + } + } + + previous = parts; + } + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/commands.h b/src/commands/commands.h index 9b6e53d2..68b10e6f 100644 --- a/src/commands/commands.h +++ b/src/commands/commands.h @@ -45,6 +45,7 @@ int CmdHelpUsage ( ); int CmdHelp (const CLI& ); int CmdImport ( ); int CmdReport (const CLI&, Rules&, Database&, const Extensions&); +int CmdShow ( Rules& ); int CmdStart (const CLI&, Rules&, Database& ); int CmdStop (const CLI&, Rules&, Database& ); int CmdTags ( Rules&, Database& );