Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: adding some CLI common code to the library
- Loading branch information
1 parent
450669b
commit bce7f12
Showing
3 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ |