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:
73
src/cli/interface/ICliParser.hpp
Normal file
73
src/cli/interface/ICliParser.hpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
ptrnt - print labels on linux
|
||||
Copyright (C) 2025 Moritz Martinius
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ptprnt::cli {
|
||||
|
||||
/**
|
||||
* @brief Types of CLI commands that can be issued
|
||||
*/
|
||||
enum class CommandType { None = 0, Text = 1, FontSize = 2, Font = 3, VAlign = 4, HAlign = 5 };
|
||||
|
||||
/**
|
||||
* @brief A command with its type and value
|
||||
*/
|
||||
using Command = std::pair<CommandType, std::string>;
|
||||
|
||||
/**
|
||||
* @brief Parsed CLI options and commands
|
||||
*/
|
||||
struct CliOptions {
|
||||
bool verbose{false};
|
||||
bool trace{false};
|
||||
bool listDrivers{false};
|
||||
std::string printerSelection{"auto"};
|
||||
std::vector<Command> commands{};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for CLI argument parsing
|
||||
*
|
||||
* This interface allows for mocking CLI parsing in unit tests
|
||||
* and provides a clear contract for CLI parser implementations.
|
||||
*/
|
||||
class ICliParser {
|
||||
public:
|
||||
virtual ~ICliParser() = default;
|
||||
|
||||
/**
|
||||
* @brief Parse command line arguments
|
||||
* @param argc Argument count
|
||||
* @param argv Argument values
|
||||
* @return 0 on success, positive value if should exit immediately (help/version), negative on error
|
||||
*/
|
||||
virtual int parse(int argc, char** argv) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get the parsed options
|
||||
* @return Reference to parsed options
|
||||
*/
|
||||
[[nodiscard]] virtual const CliOptions& getOptions() const = 0;
|
||||
};
|
||||
|
||||
} // namespace ptprnt::cli
|
||||
Reference in New Issue
Block a user