diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 3595ecce..6fc68bf2 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -5,7 +5,8 @@ include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/libshared/src ${TIMEW_INCLUDE_DIRS}) -set (commands_SRCS CmdClear.cpp +set (commands_SRCS CmdCancel.cpp + CmdClear.cpp CmdConfig.cpp CmdContinue.cpp CmdDefault.cpp diff --git a/src/commands/CmdCancel.cpp b/src/commands/CmdCancel.cpp new file mode 100644 index 00000000..2f89e0bc --- /dev/null +++ b/src/commands/CmdCancel.cpp @@ -0,0 +1,56 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 CmdCancel ( + Rules& rules, + Database& database) +{ + // If there is an open interval, cancel it. + auto latest = getLatestInterval (database); + if ( latest.range.started () && + ! latest.range.ended ()) + { + database.deleteInterval (latest); + if (rules.getBoolean ("verbose")) + std::cout << "Canceled active time tracking.\n"; + } + else + { + if (rules.getBoolean ("verbose")) + std::cout << "There is no active time tracking.\n"; + } + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/commands.h b/src/commands/commands.h index d2d8091e..bf6ec6e7 100644 --- a/src/commands/commands.h +++ b/src/commands/commands.h @@ -32,6 +32,7 @@ #include #include +int CmdCancel ( Rules&, Database& ); int CmdClear ( ); int CmdConfig ( ); int CmdContinue ( Rules&, Database& );