aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Sucan <jan@jansucan.com>2025-01-27 10:56:47 +0100
committerJán Sučan <jan@jansucan.com>2025-01-27 15:22:36 +0100
commit1a157599b63627d04a968f6251a3cde9e0cfeb7e (patch)
tree68af0167663d84ad3a330d9c4c5799f53cbd0033
parent2ef82ccca35f078973342ef132edc277bbe86a9f (diff)
Move printing usage out of OptionParser
-rw-r--r--src/main.cpp6
-rw-r--r--src/options.cpp30
-rw-r--r--src/options.h3
3 files changed, 20 insertions, 19 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 364762d..c265805 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -43,7 +43,7 @@ main(int argc, char **argv)
{
try {
if (OptionParser::isHelp(argc, argv)) {
- OptionParser::printUsage();
+ OptionsPrintUsage();
} else if (OptionParser::isVersion(argc, argv)) {
print_version();
} else if (OptionParser::isCreate(argc, argv)) {
@@ -51,11 +51,11 @@ main(int argc, char **argv)
} else if (OptionParser::isRestore(argc, argv)) {
restore(OptionParser::parseRestore(argc, argv));
} else {
- OptionParser::printUsage();
+ OptionsPrintUsage();
exit(1);
}
} catch (const OptionError &e) {
- OptionParser::printUsage();
+ OptionsPrintUsage();
std::cerr << "ERROR: " << e.what() << std::endl;
exit(1);
} catch (const DiffddError &e) {
diff --git a/src/options.cpp b/src/options.cpp
index 9b85962..baa779d 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -35,6 +35,21 @@
*/
#include "program_info.h"
+void
+OptionsPrintUsage()
+{
+ std::cout << "Usage: " << PROGRAM_NAME_STR << " create";
+ std::cout << " [-B BUFFER_SIZE] -i INFILE -b BASEFILE -o OUTFILE"
+ << std::endl;
+
+ std::cout << " Or: " << PROGRAM_NAME_STR << " restore";
+ std::cout << " [-B BUFFER_SIZE] -d DIFFFILE -o OUTFILE" << std::endl;
+
+ std::cout << " Or: " << PROGRAM_NAME_STR << " version" << std::endl;
+
+ std::cout << " Or: " << PROGRAM_NAME_STR << " help" << std::endl;
+}
+
OptionsCreate::OptionsCreate() : buffer_size{OPTIONS_DEFAULT_BUFFER_SIZE} {}
uint32_t
@@ -81,21 +96,6 @@ OptionsRestore::getOutFilePath() const
return out_file_path;
}
-void
-OptionParser::printUsage()
-{
- std::cout << "Usage: " << PROGRAM_NAME_STR << " create";
- std::cout << " [-B BUFFER_SIZE] -i INFILE -b BASEFILE -o OUTFILE"
- << std::endl;
-
- std::cout << " Or: " << PROGRAM_NAME_STR << " restore";
- std::cout << " [-B BUFFER_SIZE] -d DIFFFILE -o OUTFILE" << std::endl;
-
- std::cout << " Or: " << PROGRAM_NAME_STR << " version" << std::endl;
-
- std::cout << " Or: " << PROGRAM_NAME_STR << " help" << std::endl;
-}
-
bool
OptionParser::isHelp(int argc, char **argv)
{
diff --git a/src/options.h b/src/options.h
index c37386e..ac9fdfd 100644
--- a/src/options.h
+++ b/src/options.h
@@ -39,6 +39,8 @@ class OptionError : public DiffddError
const inline int OPTIONS_DEFAULT_BUFFER_SIZE{4 * 1024 * 1024};
+void OptionsPrintUsage();
+
class OptionsCreate
{
friend class OptionParser;
@@ -78,7 +80,6 @@ class OptionsRestore
class OptionParser
{
public:
- static void printUsage();
static bool isHelp(int argc, char **argv);
static bool isVersion(int argc, char **argv);
static bool isCreate(int argc, char **argv);