Use ArgumentParser
This commit is contained in:
parent
b9ee2180c9
commit
c73d9fe698
62
src/main.cpp
62
src/main.cpp
|
@ -1,5 +1,6 @@
|
|||
#include "image.hpp"
|
||||
#include "state.hpp"
|
||||
#include "args/args.hxx"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl.h>
|
||||
|
@ -26,6 +27,7 @@ using namespace std::chrono;
|
|||
uint16_t PORT = 8081;
|
||||
const uint16_t BUFFER_SIZE = 2048;
|
||||
int clientSocket = 0;
|
||||
unsigned int refreshMs = 1;
|
||||
|
||||
GLuint imageTexture = 0;
|
||||
GLuint blankTexture = 0;
|
||||
|
@ -203,7 +205,7 @@ void display () {
|
|||
|
||||
void timer(int value) {
|
||||
glutPostRedisplay();
|
||||
glutTimerFunc(1, timer, 0);
|
||||
glutTimerFunc(refreshMs, timer, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -260,33 +262,63 @@ void runTCPServer (int serverSocket) {
|
|||
}
|
||||
}
|
||||
|
||||
uint8_t handleArgs (int argc, char** argv) {
|
||||
if (argc > 1) {
|
||||
screenWidth = atoi(argv[1]);
|
||||
int main (int argc, char** argv) {
|
||||
args::ArgumentParser parser("filmout_display", "Displays image on a screen");
|
||||
args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"});
|
||||
args::ValueFlag<int> width(parser, "width", "Screen width (required)", {'w', "width"});
|
||||
args::ValueFlag<int> height(parser, "height", "Screen height (required)", {'H', "height"});
|
||||
args::ValueFlag<uint16_t> port(parser, "port", "Socket port (default: 8081)", {'p', "port"});
|
||||
args::ValueFlag<int> refresh(parser, "refresh", "Refresh timer in ms (default: 1)", {'r', "refresh"});
|
||||
|
||||
try
|
||||
{
|
||||
parser.ParseCLI(argc, argv);
|
||||
}
|
||||
catch (args::Help)
|
||||
{
|
||||
std::cout << parser;
|
||||
return 0;
|
||||
}
|
||||
catch (args::ParseError e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
std::cerr << parser;
|
||||
return 1;
|
||||
}
|
||||
catch (args::ValidationError e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
std::cerr << parser;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (width) {
|
||||
screenWidth = args::get(width);
|
||||
cout << "{ \"screen_width\" : " << screenWidth << " }" << endl;
|
||||
} else {
|
||||
cerr << "{ \"error\" : \"Please provide screen width as first argument\" }" << endl;
|
||||
return 1;
|
||||
}
|
||||
if (argc > 2) {
|
||||
screenHeight = atoi(argv[2]);
|
||||
|
||||
if (height) {
|
||||
screenHeight = args::get(height);
|
||||
cout << "{ \"screen_height\" : " << screenHeight << " } " << endl;
|
||||
} else {
|
||||
cerr << "{ \"error\" : \"Please provide screen height as second argument\" }" << endl;
|
||||
return 2;
|
||||
}
|
||||
if (argc > 3) {
|
||||
PORT = (uint16_t) atoi(argv[3]);
|
||||
|
||||
if (port) {
|
||||
PORT = args::get(port);
|
||||
cout << "{ \"port\" : " << PORT << " }" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc, char** argv) {
|
||||
uint8_t argsRet = handleArgs(argc, argv);
|
||||
|
||||
if (argsRet > 0) {
|
||||
return argsRet;
|
||||
if (refresh) {
|
||||
refreshMs = args::get(refresh);
|
||||
if (refreshMs < 1) {
|
||||
refreshMs = 1;
|
||||
}
|
||||
cout << "{ \"refresh\" : " << refreshMs << " }" << endl;
|
||||
}
|
||||
|
||||
img.setDimensions( (uint16_t) screenWidth, (uint16_t) screenHeight);
|
||||
|
|
Loading…
Reference in New Issue