CmdShow: Broke out config dump for a show command

This commit is contained in:
Paul Beckingham 2016-05-06 00:12:30 -04:00
parent d992de89e3
commit 5df1416f20
3 changed files with 89 additions and 0 deletions

View file

@ -23,6 +23,7 @@ set (commands_SRCS CmdCancel.cpp
CmdStart.cpp CmdStart.cpp
CmdStop.cpp CmdStop.cpp
CmdReportSummary.cpp CmdReportSummary.cpp
CmdShow.cpp
CmdTags.cpp CmdTags.cpp
CmdTrack.cpp CmdTrack.cpp
CmdUndo.cpp) CmdUndo.cpp)

87
src/commands/CmdShow.cpp Normal file
View file

@ -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 <cmake.h>
#include <shared.h>
#include <timew.h>
#include <algorithm>
#include <iostream>
////////////////////////////////////////////////////////////////////////////////
int CmdShow (Rules& rules)
{
// Obtain and sort the names. Sorting is critical.
auto names = rules.all ();
std::sort (names.begin (), names.end ());
std::vector <std::string> 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;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -45,6 +45,7 @@ int CmdHelpUsage ( );
int CmdHelp (const CLI& ); int CmdHelp (const CLI& );
int CmdImport ( ); int CmdImport ( );
int CmdReport (const CLI&, Rules&, Database&, const Extensions&); int CmdReport (const CLI&, Rules&, Database&, const Extensions&);
int CmdShow ( Rules& );
int CmdStart (const CLI&, Rules&, Database& ); int CmdStart (const CLI&, Rules&, Database& );
int CmdStop (const CLI&, Rules&, Database& ); int CmdStop (const CLI&, Rules&, Database& );
int CmdTags ( Rules&, Database& ); int CmdTags ( Rules&, Database& );