removed unsued functions in CmdParser

This commit is contained in:
Erik Frojdh 2021-09-15 08:44:48 +02:00
parent adaf56ca2e
commit ca35613b66
3 changed files with 8 additions and 53 deletions

View File

@ -10,20 +10,6 @@
namespace sls {
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';
std::cout << "\tcommand: " << command_ << '\n';
std::cout << "\tn_arguments: " << n_arguments() << '\n';
std::cout << "\targuments: ";
for (const auto &argument : arguments_) {
std::cout << argument << " ";
}
std::cout << "\n\n";
};
void CmdParser::Parse(int argc, const char *const argv[]) {
Reset();
executable_ = argv[0]; // first arg is calling binary
@ -108,28 +94,10 @@ void CmdParser::DecodeIdAndPosition(std::string pre){
}
std::vector<const char *> CmdParser::argv() const {
std::vector<const char *> vec;
if (!command_.empty()) {
vec.push_back(&command_.front());
}
for (auto &arg : arguments_) {
vec.push_back(&arg.front());
}
return vec;
}
std::string CmdParser::cli_line() const {
std::ostringstream os;
os << command_;
for (const auto &arg : arguments_)
os << " " << arg;
return os.str();
}
void CmdParser::Reset() {
multi_id_ = 0;
detector_id_ = -1;
receiver_id_ = -1;
help_ = false;
command_.clear();
executable_.clear();

View File

@ -23,7 +23,6 @@ class CmdParser {
public:
void Parse(int argc, const char *const argv[]);
void Parse(std::string s);
void Print();
int multi_id() const noexcept { return multi_id_; };
int detector_id() const noexcept { return detector_id_; };
@ -37,8 +36,6 @@ class CmdParser {
const std::vector<std::string> &arguments() const noexcept {
return arguments_;
};
std::vector<const char *> argv() const;
std::string cli_line() const;
private:
void DecodeIdAndPosition(std::string pre);

View File

@ -18,8 +18,8 @@ SCENARIO("Construction", "[support]") {
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command().empty());
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().empty());
REQUIRE(p.argv().data() == nullptr);
// REQUIRE(p.argv().empty());
// REQUIRE(p.argv().data() == nullptr);
}
}
}
@ -35,7 +35,7 @@ SCENARIO("Parsing a string with the command line parser", "[support]") {
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command().empty());
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().empty());
// REQUIRE(p.argv().empty());
}
}
WHEN("Parsing a string with a single command") {
@ -46,7 +46,7 @@ SCENARIO("Parsing a string with the command line parser", "[support]") {
REQUIRE(p.detector_id() == -1);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().size() == 1);
// REQUIRE(p.argv().size() == 1);
}
}
WHEN("Parsing a string with command and value") {
@ -72,7 +72,7 @@ SCENARIO("Parsing a string with the command line parser", "[support]") {
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command() == res[i]);
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().size() == 1);
// REQUIRE(p.argv().size() == 1);
}
}
}
@ -89,7 +89,7 @@ SCENARIO("Parsing a string with the command line parser", "[support]") {
REQUIRE(p.multi_id() == multi_id[i]);
REQUIRE(p.command() == res[i]);
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().size() == 1);
// REQUIRE(p.argv().size() == 1);
}
}
}
@ -121,7 +121,7 @@ SCENARIO("Parsing strings with -h or --help", "[support]") {
REQUIRE(p.command() == "list");
REQUIRE(p.isHelp());
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().size() == 1);
// REQUIRE(p.argv().size() == 1);
}
}
WHEN("Parsing a string with -h at a different position") {
@ -271,16 +271,6 @@ TEST_CASE("Double digit id", "[support]") {
}
TEST_CASE("Build up argv", "[support]") {
CmdParser p;
REQUIRE(p.argv().empty());
REQUIRE(p.argv().data() == nullptr);
std::string s = "trimen 3000 4000\n";
p.Parse(s);
REQUIRE(p.argv().data() != nullptr);
REQUIRE(p.argv().size() == 3);
}
TEST_CASE("Allows space between mod id and command"){
CmdParser p;