Skip to content

Commit

Permalink
lib: adding some CLI common code to the library
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri committed Jul 11, 2022
1 parent 450669b commit bce7f12
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/src/lib/CMakeLists.txt
Expand Up @@ -48,6 +48,7 @@ set(BAREOS_SRCS
btime.cc
btimers.cc
cbuf.cc
cli.cc
connection_pool.cc
cram_md5.cc
crypto.cc
Expand Down Expand Up @@ -155,9 +156,11 @@ target_compile_definitions(
set_target_properties(version-obj PROPERTIES POSITION_INDEPENDENT_CODE ON)

target_link_libraries(
bareos PRIVATE bareosfastlz ${OPENSSL_LIBRARIES} Threads::Threads
${ZLIB_LIBRARIES} ${LZO2_LIBRARIES} ${CAM_LIBRARIES}
bareos
PRIVATE bareosfastlz ${OPENSSL_LIBRARIES} Threads::Threads ${ZLIB_LIBRARIES}
${LZO2_LIBRARIES} ${CAM_LIBRARIES} CLI11::CLI11
)

if(ENABLE_CAPABILITY)
target_link_libraries(bareos PRIVATE ${CAP_LIBRARIES})
endif()
Expand Down
58 changes: 58 additions & 0 deletions core/src/lib/cli.cc
@@ -0,0 +1,58 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2022-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program 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
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/

#include "cli.h"
#include "lib/version.h"
#include "lib/message.h"

void InitCLIApp(CLI::App& app, std::string description, int fsfyear)
{
if (fsfyear) {
std::vector<char> copyright(1024);
kBareosVersionStrings.FormatCopyrightWithFsfAndPlanets(
copyright.data(), copyright.size(), fsfyear);

description += "\n" + std::string(copyright.data());
}

app.description(description);
app.set_help_flag("-h,--help,-?", "Print this help message and exit.");
app.set_version_flag("--version", kBareosVersionStrings.Full);
app.get_formatter()->column_width(40);
#ifdef HAVE_WIN32
app.allow_windows_style_options();
#endif
}

void AddDebugOptions(CLI::App& app)
{
app.add_option("-d,--debug-level", debug_level, "Set debug level to <level>.")
->check(CLI::NonNegativeNumber)
->type_name("<level>");

app.add_flag("--dt,--debug-timestamps", dbg_timestamp,
"Print timestamps in debug output.");
}

void AddVerboseOption(CLI::App& app)
{
app.add_flag("-v,--verbose", verbose, "Verbose user messages.");
}
32 changes: 32 additions & 0 deletions core/src/lib/cli.h
@@ -0,0 +1,32 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2022-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program 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
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef BAREOS_LIB_CLI_H_
#define BAREOS_LIB_CLI_H_

#include "CLI/App.hpp"
#include "CLI/Config.hpp"
#include "CLI/Formatter.hpp"

void InitCLIApp(CLI::App& app, std::string description, int fsfyear = 0);
void AddDebugOptions(CLI::App& app);
void AddVerboseOption(CLI::App& app);

#endif // BAREOS_LIB_CLI_H_

0 comments on commit bce7f12

Please sign in to comment.