added man page support

pull/1/head
Michael Ochmann 2 years ago
parent dd45505f21
commit 2a8e54610b
  1. 8
      CMakeLists.txt
  2. 75
      main.cpp
  3. 10
      src/QR.cpp
  4. 3
      src/QR.hpp

@ -27,5 +27,13 @@ set_target_properties(qr PROPERTIES OUTPUT_NAME ${EXE_NAME})
target_compile_options(qr PUBLIC -Wall -std=c++20 -arch ${ARCH}) target_compile_options(qr PUBLIC -Wall -std=c++20 -arch ${ARCH})
target_include_directories(qr PRIVATE src lib) target_include_directories(qr PRIVATE src lib)
add_custom_target(man ALL)
add_custom_command(
TARGET man
COMMAND help2man -h "-h" -v "-v" -o qr.7 ${EXE_NAME}
COMMAND gzip -f qr.7
)
install(TARGETS qr RUNTIME DESTINATION bin) install(TARGETS qr RUNTIME DESTINATION bin)
install(PROGRAMS build/${EXE_NAME} DESTINATION bin RENAME qr) install(PROGRAMS build/${EXE_NAME} DESTINATION bin RENAME qr)
install(FILES build/qr.7.gz DESTINATION /usr/local/share/man/man7/)

@ -12,20 +12,39 @@ constexpr const char* VERSION = "@qr_VERSION@";
void printHelp() { void printHelp() {
std::string helpText = R"EOF( std::string helpText = R"EOF(
(C) 2023, MikO <miko@massivedynamic.eu>
a tool for generating QR codes qr is a tool for generating QR codes from the commandline
Released under MIT license.
Usage: qr [OPTION]... --input "data to encapsulate"
Usage:
-f --format output file format. can be one of "cli, png, svg, jpg, bmp" *Caveats*
-h --help show this help With no `--input` parameter defined, read STDIN
-i --input take data from this argument instead of stdin
-o --output output file name without extension In pixel based renderers (i.e. PNG), the output size may not be exactly as
-s --size desired output file size in pixels specified but be the nearest multiple of the actual cell size for the QR code.
-t --type output QR code type. can be one of "small, medium, large"
Options:
In pixel based renderers (i.e. PNG), the output size may not be exactly as -f --format output file format. can be one of "cli, png, svg, jpg, bmp"
specified but be the nearest multiple of the actual cell size for the QR code. -h --help show this help
-i --input take data from this argument instead of stdin
-o --output output file name without extension
-s --size desired output file size in pixels
-t --type output QR code type. can be one of "small, medium, large"
-v --version shows version info
Examples:
qr -i "this is from parameter" -f png -s 512 -o my_qrcode_file
echo "this is from stdin" | qr -t small -f png -s 512 -o my_qrcode_file_with_low_ecc
Copyright:
(C) 2023, MikO <miko@massivedynamic.eu>
*License*
Released under MIT license
Report bugs and issues at out issue tracker:
https://git.mike-ochmann.de/MassiveDynamic/qr/issues
)EOF"; )EOF";
std::cout << "qr " << VERSION; std::cout << "qr " << VERSION;
std::cout << helpText << std::endl; std::cout << helpText << std::endl;
@ -37,26 +56,27 @@ int main(int argc, char* argv[]) {
exit(1); exit(1);
} }
const option options[] = { const option options[] = {
{"help", no_argument, nullptr, 'h'}, {"help", no_argument, nullptr, 'h'},
{"input", required_argument, nullptr, 'i'}, {"input", required_argument, nullptr, 'i'},
{"output", required_argument, nullptr, 'o'}, {"output", required_argument, nullptr, 'o'},
{"size", required_argument, nullptr, 's'}, {"size", required_argument, nullptr, 's'},
{"type", required_argument, nullptr, 't'}, {"type", required_argument, nullptr, 't'},
{"format", required_argument, nullptr, 'f'}, {"format", required_argument, nullptr, 'f'},
{"version", no_argument, nullptr, 'v'},
{nullptr} {nullptr}
}; };
std::string outputFile; std::string outputFile;
std::string paramData;
size_t segmentSize = 0; size_t segmentSize = 0;
massivedynamic::Type type = massivedynamic::Type::MEDIUM;
massivedynamic::Format format = massivedynamic::Format::CONSOLE;
bool fromStdin = true; bool fromStdin = true;
bool anyParameterSet = false; bool anyParameterSet = false;
std::string paramData = ""; massivedynamic::Type type = massivedynamic::Type::MEDIUM;
massivedynamic::Format format = massivedynamic::Format::CONSOLE;
for(;;) { for(;;) {
int index = -1; int index = -1;
int result = getopt_long(argc, argv, "ho:s:t:f:i:", options, &index); int result = getopt_long(argc, argv, "vho:s:t:f:i:", options, &index);
if (result == -1) if (result == -1)
break; break;
@ -112,6 +132,10 @@ int main(int argc, char* argv[]) {
paramData = optarg; paramData = optarg;
break; break;
} }
case 'v': {
std::cout << "qr " << VERSION << std::endl;
exit(0);
}
case 'h': case 'h':
default: default:
printHelp(); printHelp();
@ -152,7 +176,8 @@ int main(int argc, char* argv[]) {
return 1; return 1;
} }
std::unique_ptr<massivedynamic::QR> qr = std::make_unique<massivedynamic::QR>(data.str(), outputFile, segmentSize, type, format); std::unique_ptr<massivedynamic::QR> qr = std::make_unique<massivedynamic::QR>(data.str(), outputFile, segmentSize, type);
qr->render(format);
return 0; return 0;
} }

@ -12,7 +12,7 @@
namespace massivedynamic { namespace massivedynamic {
QR::QR(const std::string& data, std::string outputFile, size_t size, Type type, Format format) : outputFile(std::move(outputFile)) { QR::QR(const std::string& data, std::string outputFile, size_t size, Type type) : outputFile(std::move(outputFile)) {
qrcodegen::QrCode::Ecc errorCorrectionLevel = qrcodegen::QrCode::Ecc::HIGH; qrcodegen::QrCode::Ecc errorCorrectionLevel = qrcodegen::QrCode::Ecc::HIGH;
@ -45,6 +45,14 @@ QR::QR(const std::string& data, std::string outputFile, size_t size, Type type,
this->pixels.push_back(qr.getModule(x, y)); this->pixels.push_back(qr.getModule(x, y));
} }
}
void QR::render(Format format) {
if (this->renderers.find(format) == this->renderers.end()) {
std::cerr << "ERROR: a non-valid renderer has been selected" << std::endl;
exit(1);
}
this->renderers.at(format)->render(this->outputFile); this->renderers.at(format)->render(this->outputFile);
} }

@ -34,7 +34,8 @@ namespace massivedynamic {
std::vector<bool> pixels; std::vector<bool> pixels;
std::unordered_map<Format, std::unique_ptr<Renderer>> renderers; std::unordered_map<Format, std::unique_ptr<Renderer>> renderers;
public: public:
QR(const std::string& data, std::string outputFile, size_t size, Type type, Format format); QR(const std::string& data, std::string outputFile, size_t size, Type type);
void render(Format format);
}; };
} }
Loading…
Cancel
Save