cli-parser-cleanup (#15)
All checks were successful
Build ptprnt / build (push) Successful in 3m50s
All checks were successful
Build ptprnt / build (push) Successful in 3m50s
Reviewed-on: moritz/ptouch-prnt#15
This commit was merged in pull request #15.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
ptrnt - print labels on linux
|
||||
Copyright (C) 2023-2025 Moritz Martinius
|
||||
|
||||
@@ -19,49 +19,75 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <CLI/CLI.hpp>
|
||||
#include <spdlog/common.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "interface/IPrinterDriver.hpp"
|
||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||
namespace ptprnt::cli {
|
||||
class ICliParser;
|
||||
}
|
||||
|
||||
namespace ptprnt::core {
|
||||
class IPrinterService;
|
||||
}
|
||||
|
||||
namespace ptprnt {
|
||||
enum class CliCmdType { None = 0, Text = 1, FontSize = 2, Font = 3, VAlign = 4, HAlign = 5 };
|
||||
using CliCmd = std::pair<CliCmdType, std::string>;
|
||||
|
||||
/**
|
||||
* @brief Main application class for ptprnt
|
||||
*
|
||||
* Acts as a thin glue layer coordinating CLI parsing and core printer functionality.
|
||||
* Separates CLI frontend concerns from the core library.
|
||||
*
|
||||
* Uses interfaces (ICliParser, IPrinterService) to enable dependency injection
|
||||
* and facilitate unit testing with mocks.
|
||||
*/
|
||||
class PtouchPrint {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct the application with default implementations
|
||||
* @param versionString Version string to display
|
||||
*/
|
||||
PtouchPrint(const char* versionString);
|
||||
~PtouchPrint() = default;
|
||||
|
||||
// This is basically a singelton application class, no need to copy or move
|
||||
/**
|
||||
* @brief Construct with custom implementations (for testing)
|
||||
* @param versionString Version string to display
|
||||
* @param cliParser Custom CLI parser implementation
|
||||
* @param printerService Custom printer service implementation
|
||||
*/
|
||||
PtouchPrint(const char* versionString, std::unique_ptr<cli::ICliParser> cliParser,
|
||||
std::unique_ptr<core::IPrinterService> printerService);
|
||||
|
||||
~PtouchPrint(); // Must be defined in .cpp where complete types are visible
|
||||
|
||||
// This is basically a singleton application class, no need to copy or move
|
||||
PtouchPrint(const PtouchPrint&) = delete;
|
||||
PtouchPrint& operator=(const PtouchPrint&) = delete;
|
||||
PtouchPrint(PtouchPrint&&) = delete;
|
||||
PtouchPrint& operator=(PtouchPrint&&) = delete;
|
||||
|
||||
/**
|
||||
* @brief Initialize the application
|
||||
* @param argc Argument count
|
||||
* @param argv Argument values
|
||||
* @return 0 on success, non-zero on error
|
||||
*/
|
||||
int init(int argc, char** argv);
|
||||
|
||||
/**
|
||||
* @brief Run the application
|
||||
* @return 0 on success, non-zero on error
|
||||
*/
|
||||
int run();
|
||||
|
||||
private:
|
||||
// methods
|
||||
void setupLogger(spdlog::level::level_enum lvl);
|
||||
void setupCliParser();
|
||||
std::vector<std::shared_ptr<IPrinterDriver>> getCompatiblePrinters();
|
||||
void setupLogger();
|
||||
bool handleListDrivers();
|
||||
bool handlePrinting();
|
||||
|
||||
// member variables
|
||||
CLI::App mApp{ptprnt::APP_DESC};
|
||||
libusbwrap::UsbDeviceFactory mUsbDeviceFactory{};
|
||||
std::vector<std::shared_ptr<IPrinterDriver>> mDetectedPrinters{};
|
||||
std::vector<CliCmd> mCommands{};
|
||||
std::string mVersionString = "";
|
||||
|
||||
// CLI flags and options
|
||||
bool mVerboseFlag = false;
|
||||
bool mTraceFlag = false;
|
||||
std::string mPrinterSelection = "auto";
|
||||
bool mListDriversFlag = false;
|
||||
std::string mVersionString;
|
||||
std::unique_ptr<cli::ICliParser> mCliParser;
|
||||
std::unique_ptr<core::IPrinterService> mPrinterService;
|
||||
};
|
||||
} // namespace ptprnt
|
||||
|
||||
} // namespace ptprnt
|
||||
|
||||
Reference in New Issue
Block a user