Browse Source

Add some functions for accessing command line parameters

pull/2/head
Nubben 5 years ago
parent
commit
3ef966b2b5
  1. 27
      src/CommandLineParams.cpp
  2. 14
      src/CommandLineParams.h
  3. 2
      src/main.cpp

27
src/CommandLineParams.cpp

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
#include "CommandLineParams.h"
#include <vector>
namespace {
std::vector<std::string> params;
}
void initCLParams(int argc, char *argv[]) {
params = std::vector<std::string> (argv, argv + argc);
}
bool getCLParam(std::string const& param) {
for (auto const& p : params) {
if (p == param) {
return true;
}
}
return false;
}
std::string getCLParamByIndex(unsigned int i) {
if (i < params.size()) {
return params[i];
}
return "";
}

14
src/CommandLineParams.h

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
#ifndef COMMANDLINEPARAMS_H
#define COMMANDLINEPARAMS_H
#include <string>
void initCLParams(int argc, char *argv[]);
// USAGE: getCLParam("-example")
bool getCLParam(std::string const& param);
// 0 is the program name
std::string getCLParamByIndex(unsigned int i);
#endif

2
src/main.cpp

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
#include <memory>
#include "StringUtils.h"
#include "WebResource.h"
#include "CommandLineParams.h"
void handleRequest(const HTTPResponse &response);
@ -128,6 +129,7 @@ int main(int argc, char *argv[]) { @@ -128,6 +129,7 @@ int main(int argc, char *argv[]) {
std::cout << "./netrunner <url|file.html>" << std::endl;
return 1;
}
initCLParams(argc, argv);
std::cout << "/g/ntr - NetRunner build " << __DATE__ << std::endl;
currentURL=argv[1];

Loading…
Cancel
Save