moved CmdLineParser to sls::

This commit is contained in:
Erik Frojdh 2019-08-23 10:42:35 +02:00
parent 6a20a780fe
commit 57ac5c0dab
4 changed files with 19 additions and 11 deletions

View File

@ -15,7 +15,7 @@ class multiSlsDetectorClient {
private: private:
int action_; int action_;
CmdLineParser parser; sls::CmdLineParser parser;
multiSlsDetector *detPtr = nullptr; multiSlsDetector *detPtr = nullptr;
std::ostream &os; std::ostream &os;

View File

@ -4,9 +4,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace sls {
class CmdLineParser { class CmdLineParser {
public: public:
void Parse(int argc, const char * const argv[]); void Parse(int argc, const char *const argv[]);
void Parse(const std::string &s); void Parse(const std::string &s);
void Print(); void Print();
@ -14,8 +16,8 @@ class CmdLineParser {
int detector_id() const { return detector_id_; }; int detector_id() const { return detector_id_; };
int n_arguments() const { return arguments_.size(); } int n_arguments() const { return arguments_.size(); }
const std::string &command() const { return command_; } const std::string &command() const { return command_; }
bool isHelp() const{return help_;} bool isHelp() const { return help_; }
void setCommand(std::string cmd){command_ = cmd;} void setCommand(std::string cmd) { command_ = cmd; }
const std::string &executable() const { return executable_; } const std::string &executable() const { return executable_; }
const std::vector<std::string> &arguments() const { return arguments_; }; const std::vector<std::string> &arguments() const { return arguments_; };
std::vector<const char *> argv() const; std::vector<const char *> argv() const;
@ -30,4 +32,5 @@ class CmdLineParser {
std::vector<std::string> arguments_; std::vector<std::string> arguments_;
}; };
} // namespace sls
#endif // CMD_LINE_PARSER_H #endif // CMD_LINE_PARSER_H

View File

@ -7,6 +7,8 @@
#include <iterator> #include <iterator>
#include <sstream> #include <sstream>
namespace sls {
void CmdLineParser::Print() { void CmdLineParser::Print() {
std::cout << "\nCmdLineParser::Print()\n"; std::cout << "\nCmdLineParser::Print()\n";
std::cout << "\tmulti_id: " << multi_id_ std::cout << "\tmulti_id: " << multi_id_
@ -40,15 +42,15 @@ void CmdLineParser::Parse(const std::string &s) {
std::vector<std::string>(it, std::istream_iterator<std::string>()); std::vector<std::string>(it, std::istream_iterator<std::string>());
auto old_size = arguments_.size(); auto old_size = arguments_.size();
arguments_.erase(std::remove_if(begin(arguments_), end(arguments_), arguments_.erase(std::remove_if(begin(arguments_), end(arguments_),
[](const std::string &item) { [](const std::string &item) {
if (item == "-h" || item == "--help") if (item == "-h" || item == "--help")
return true; return true;
return false; return false;
}), }),
end(arguments_)); end(arguments_));
if (old_size - arguments_.size() > 0) if (old_size - arguments_.size() > 0)
help_ = true; help_ = true;
if(!arguments_.empty()){ if (!arguments_.empty()) {
command_ = arguments_[0]; command_ = arguments_[0];
arguments_.erase(begin(arguments_)); arguments_.erase(begin(arguments_));
} }
@ -97,3 +99,5 @@ std::vector<const char *> CmdLineParser::argv() const {
} }
return vec; return vec;
} }
} // namespace sls

View File

@ -9,6 +9,7 @@
// command for all depreciated commands // command for all depreciated commands
using vs = std::vector<std::string>; using vs = std::vector<std::string>;
using sls::CmdLineParser;
SCENARIO("Construction", "[support]") { SCENARIO("Construction", "[support]") {
GIVEN("A default constructed CmdLineParser") { GIVEN("A default constructed CmdLineParser") {