Add name paramater to options
This commit is contained in:
parent
426fcf43c4
commit
96d9c1b759
@ -18,10 +18,8 @@ int main(int argc, char** argv){
|
|||||||
|
|
||||||
setRoutes(app);
|
setRoutes(app);
|
||||||
|
|
||||||
std::cerr << "Setting up app" << std::endl;
|
|
||||||
|
|
||||||
app.port(flags->port)
|
app.port(flags->port)
|
||||||
.server_name("proc_api")
|
.server_name(flags->name)
|
||||||
.multithreaded();
|
.multithreaded();
|
||||||
|
|
||||||
delete flags;
|
delete flags;
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
void help(char* progName){
|
void help(char* progName){
|
||||||
std::cout << "Usage: " << progName << " [FLAGS]\n";
|
std::cout << "Usage: " << progName << " [FLAGS]\n";
|
||||||
std::cout << "Options:\n";
|
std::cout << "Options:\n";
|
||||||
std::cout << " [-p] Port to listen on\n";
|
std::cout << " [-p PORT] Port to listen on (Default 5000)\n";
|
||||||
|
std::cout << " [-n NAME] Server name (Default \"proc-api\")\n";
|
||||||
std::cout << " [-h] Display this help message\n\n";
|
std::cout << " [-h] Display this help message\n\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -20,13 +21,16 @@ option_flags* parse_options(int argc, char** argv){
|
|||||||
option_flags* ret = new option_flags;
|
option_flags* ret = new option_flags;
|
||||||
|
|
||||||
ret->port = 5000;
|
ret->port = 5000;
|
||||||
|
ret->name = "proc-api";
|
||||||
|
|
||||||
while((c = getopt(argc, argv, optarg_string)) != -1){
|
while((c = getopt(argc, argv, optarg_string)) != -1){
|
||||||
switch(c){
|
switch(c){
|
||||||
case 'p':
|
case 'p':
|
||||||
std::cout << optarg << "\n";
|
|
||||||
ret->port = atoi(optarg);
|
ret->port = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'n':
|
||||||
|
ret->name = std::string(optarg);
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
std::cerr << "Unkown option: " << (char)optopt << "\n";
|
std::cerr << "Unkown option: " << (char)optopt << "\n";
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -12,10 +12,11 @@
|
|||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
// cli options
|
// cli options
|
||||||
|
|
||||||
constexpr char optarg_string[] = "p:h";
|
constexpr char optarg_string[] = "n:p:h";
|
||||||
|
|
||||||
struct option_flags {
|
struct option_flags {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
void help(char*);
|
void help(char*);
|
||||||
|
Loading…
Reference in New Issue
Block a user