mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 22:40:02 +02:00
renamed CmdLineParser to CmdParser
This commit is contained in:
parent
e996068328
commit
a28fa66e54
@ -4,7 +4,7 @@ set(SOURCES
|
||||
src/slsDetector.cpp
|
||||
src/Detector.cpp
|
||||
src/CmdProxy.cpp
|
||||
src/CmdLineParser.cpp
|
||||
src/CmdParser.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
|
@ -1,5 +1,11 @@
|
||||
|
||||
#include "CmdLineParser.h"
|
||||
/*
|
||||
This file is used to generate the command line binaries
|
||||
(sls_detector_get/put/acquire/help). By defines in CMake
|
||||
we get the different files.
|
||||
|
||||
*/
|
||||
#include "CmdParser.h"
|
||||
#include "CmdProxy.h"
|
||||
#include "Detector.h"
|
||||
#include "sls_detector_defs.h"
|
||||
@ -35,7 +41,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
sls::CmdLineParser parser;
|
||||
sls::CmdParser parser;
|
||||
parser.Parse(argc, argv);
|
||||
|
||||
// If we called sls_detector_acquire, add the acquire command
|
||||
@ -57,11 +63,11 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
try {
|
||||
//How big should this try block be?
|
||||
// How big should this try block be?
|
||||
sls::Detector det(parser.multi_id());
|
||||
sls::CmdProxy proxy(&det);
|
||||
proxy.Call(parser.command(), parser.arguments(),
|
||||
parser.detector_id(), action);
|
||||
proxy.Call(parser.command(), parser.arguments(), parser.detector_id(),
|
||||
action);
|
||||
} catch (const sls::RuntimeError &e) {
|
||||
// OK to catch and do nothing since this will print the error message
|
||||
// and command line app will anyway exit
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
#include "CmdLineParser.h"
|
||||
#include "CmdParser.h"
|
||||
#include "sls_detector_defs.h"
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
@ -9,8 +9,8 @@
|
||||
|
||||
namespace sls {
|
||||
|
||||
void CmdLineParser::Print() {
|
||||
std::cout << "\nCmdLineParser::Print()\n";
|
||||
void CmdParser::Print() {
|
||||
std::cout << "\nCmdParser::Print()\n";
|
||||
std::cout << "\tmulti_id: " << multi_id_
|
||||
<< ", detector_id: " << detector_id_ << std::endl;
|
||||
std::cout << "\texecutable: " << executable_ << '\n';
|
||||
@ -23,7 +23,7 @@ void CmdLineParser::Print() {
|
||||
std::cout << "\n\n";
|
||||
};
|
||||
|
||||
void CmdLineParser::Parse(int argc, const char *const argv[]) {
|
||||
void CmdParser::Parse(int argc, const char *const argv[]) {
|
||||
Reset();
|
||||
executable_ = argv[0]; // first arg is calling binary
|
||||
if (argc > 1) {
|
||||
@ -36,7 +36,7 @@ void CmdLineParser::Parse(int argc, const char *const argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
void CmdLineParser::Parse(const std::string &s) {
|
||||
void CmdParser::Parse(const std::string &s) {
|
||||
Reset();
|
||||
std::istringstream iss(s);
|
||||
auto it = std::istream_iterator<std::string>(iss);
|
||||
@ -59,7 +59,7 @@ void CmdLineParser::Parse(const std::string &s) {
|
||||
DecodeIdAndPosition(command_.c_str());
|
||||
}
|
||||
|
||||
void CmdLineParser::DecodeIdAndPosition(const char *c) {
|
||||
void CmdParser::DecodeIdAndPosition(const char *c) {
|
||||
bool contains_id = std::strchr(c, '-') != nullptr;
|
||||
bool contains_pos = std::strchr(c, ':') != nullptr;
|
||||
char tmp[100];
|
||||
@ -91,7 +91,7 @@ void CmdLineParser::DecodeIdAndPosition(const char *c) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<const char *> CmdLineParser::argv() const {
|
||||
std::vector<const char *> CmdParser::argv() const {
|
||||
std::vector<const char *> vec;
|
||||
if (command_.empty() != true) {
|
||||
vec.push_back(&command_.front());
|
||||
@ -103,7 +103,7 @@ std::vector<const char *> CmdLineParser::argv() const {
|
||||
}
|
||||
|
||||
|
||||
std::string CmdLineParser::cli_line() const{
|
||||
std::string CmdParser::cli_line() const{
|
||||
std::ostringstream os;
|
||||
os << command_;
|
||||
for (const auto & arg : arguments_)
|
||||
@ -111,7 +111,7 @@ std::string CmdLineParser::cli_line() const{
|
||||
return os.str();
|
||||
}
|
||||
|
||||
void CmdLineParser::Reset(){
|
||||
void CmdParser::Reset(){
|
||||
multi_id_ = 0;
|
||||
detector_id_ = -1;
|
||||
help_ = false;
|
@ -19,7 +19,7 @@ reason that the header file is not exposed.
|
||||
|
||||
namespace sls {
|
||||
|
||||
class CmdLineParser {
|
||||
class CmdParser {
|
||||
public:
|
||||
void Parse(int argc, const char *const argv[]);
|
||||
void Parse(const std::string &s);
|
@ -1,5 +1,5 @@
|
||||
#include "Detector.h"
|
||||
#include "CmdLineParser.h"
|
||||
#include "CmdParser.h"
|
||||
#include "CmdProxy.h"
|
||||
#include "container_utils.h"
|
||||
#include "detectorData.h"
|
||||
@ -58,7 +58,7 @@ void Detector::loadConfig(const std::string &fname) {
|
||||
|
||||
void Detector::loadParameters(const std::string &fname) {
|
||||
CmdProxy proxy(this);
|
||||
CmdLineParser parser;
|
||||
CmdParser parser;
|
||||
std::ifstream input_file;
|
||||
input_file.open(fname.c_str(), std::ios_base::in);
|
||||
if (!input_file.is_open()) {
|
||||
|
@ -6,7 +6,7 @@ target_sources(tests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-CmdProxy-eiger.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-CmdProxy-jungfrau.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-Result.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-CmdLineParser.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-CmdParser.cpp
|
||||
)
|
||||
|
||||
target_include_directories(tests PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src>")
|
@ -1,4 +1,4 @@
|
||||
#include "CmdLineParser.h"
|
||||
#include "CmdParser.h"
|
||||
#include "catch.hpp"
|
||||
#include <exception>
|
||||
#include <string>
|
||||
@ -9,11 +9,11 @@
|
||||
// command for all depreciated commands
|
||||
|
||||
using vs = std::vector<std::string>;
|
||||
using sls::CmdLineParser;
|
||||
using sls::CmdParser;
|
||||
|
||||
SCENARIO("Construction", "[support]") {
|
||||
GIVEN("A default constructed CmdLineParser") {
|
||||
CmdLineParser p;
|
||||
GIVEN("A default constructed CmdParser") {
|
||||
CmdParser p;
|
||||
THEN("The state of the object is valid") {
|
||||
REQUIRE(p.detector_id() == -1);
|
||||
REQUIRE(p.multi_id() == 0);
|
||||
@ -26,8 +26,8 @@ SCENARIO("Construction", "[support]") {
|
||||
}
|
||||
|
||||
SCENARIO("Parsing a string with the command line parser", "[support]") {
|
||||
GIVEN("A CmdLineParser") {
|
||||
CmdLineParser p;
|
||||
GIVEN("A CmdParser") {
|
||||
CmdParser p;
|
||||
WHEN("Parsing an empty string") {
|
||||
std::string s;
|
||||
p.Parse(s);
|
||||
@ -121,7 +121,7 @@ SCENARIO("Parsing a string with the command line parser", "[support]") {
|
||||
|
||||
SCENARIO("Parsing strings with -h or --help", "[support]") {
|
||||
GIVEN("A parser") {
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
WHEN("Parsing a string with a command and help ") {
|
||||
std::string s = "-h list";
|
||||
|
||||
@ -159,7 +159,7 @@ SCENARIO("Parsing strings with -h or --help", "[support]") {
|
||||
}
|
||||
|
||||
TEST_CASE("Parsing consecutive strings resets not found det id"){
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
p.Parse("1:exptime 0.5");
|
||||
REQUIRE(p.detector_id() == 1);
|
||||
p.Parse("exptime 0.5");
|
||||
@ -170,7 +170,7 @@ TEST_CASE("Parsing consecutive strings resets not found det id"){
|
||||
}
|
||||
|
||||
TEST_CASE("Parsing consecutive strings resets not found multi id"){
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
p.Parse("1-1:exptime 0.5");
|
||||
REQUIRE(p.multi_id() == 1);
|
||||
p.Parse("1:exptime 0.5");
|
||||
@ -183,7 +183,7 @@ TEST_CASE("Parse with no arguments results in no command and default id",
|
||||
// first argument is the command used to call the binary
|
||||
int argc = 1;
|
||||
const char *const argv[]{"call"};
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
p.Parse(argc, argv);
|
||||
|
||||
REQUIRE(p.detector_id() == -1);
|
||||
@ -197,7 +197,7 @@ TEST_CASE(
|
||||
"[support]") {
|
||||
int argc = 2;
|
||||
const char *const argv[]{"caller", "vrf"};
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
p.Parse(argc, argv);
|
||||
|
||||
REQUIRE(p.detector_id() == -1);
|
||||
@ -210,7 +210,7 @@ TEST_CASE("Parse a command with value but without client or detector id",
|
||||
"[support]") {
|
||||
int argc = 3;
|
||||
const char *const argv[]{"caller", "vrf", "3000"};
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
p.Parse(argc, argv);
|
||||
|
||||
REQUIRE(p.detector_id() == -1);
|
||||
@ -224,7 +224,7 @@ TEST_CASE("Decodes position") {
|
||||
int argc = 2;
|
||||
const char *const argv[]{"caller", "7:vrf"};
|
||||
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
p.Parse(argc, argv);
|
||||
|
||||
REQUIRE(p.detector_id() == 7);
|
||||
@ -236,7 +236,7 @@ TEST_CASE("Decodes position") {
|
||||
TEST_CASE("Decodes double digit position", "[support]") {
|
||||
int argc = 2;
|
||||
const char *const argv[]{"caller", "73:vcmp"};
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
p.Parse(argc, argv);
|
||||
|
||||
REQUIRE(p.detector_id() == 73);
|
||||
@ -248,7 +248,7 @@ TEST_CASE("Decodes double digit position", "[support]") {
|
||||
TEST_CASE("Decodes position and id", "[support]") {
|
||||
int argc = 2;
|
||||
const char *const argv[]{"caller", "5-8:vrf"};
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
p.Parse(argc, argv);
|
||||
|
||||
REQUIRE(p.detector_id() == 8);
|
||||
@ -260,7 +260,7 @@ TEST_CASE("Decodes position and id", "[support]") {
|
||||
TEST_CASE("Double digit id", "[support]") {
|
||||
int argc = 2;
|
||||
const char *const argv[]{"caller", "56-8:vrf"};
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
p.Parse(argc, argv);
|
||||
REQUIRE(p.detector_id() == 8);
|
||||
REQUIRE(p.multi_id() == 56);
|
||||
@ -271,19 +271,19 @@ TEST_CASE("Double digit id", "[support]") {
|
||||
TEST_CASE("Calling with wrong id throws invalid_argument", "[support]") {
|
||||
int argc = 2;
|
||||
const char *const argv[]{"caller", "asvldkn:vrf"};
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
CHECK_THROWS(p.Parse(argc, argv));
|
||||
}
|
||||
|
||||
TEST_CASE("Calling with wrong client throws invalid_argument", "[support]") {
|
||||
int argc = 2;
|
||||
const char *const argv[]{"caller", "lki-3:vrf"};
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
CHECK_THROWS(p.Parse(argc, argv));
|
||||
}
|
||||
|
||||
TEST_CASE("Build up argv", "[support]") {
|
||||
CmdLineParser p;
|
||||
CmdParser p;
|
||||
REQUIRE(p.argv().empty());
|
||||
REQUIRE(p.argv().data() == nullptr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user