Skip to content

Commit

Permalink
resolve issues with parseArgs and Subcall base class to ensure usabil…
Browse files Browse the repository at this point in the history
…ity without redundancy
  • Loading branch information
riasc committed Nov 15, 2024
1 parent 000e618 commit 505b909
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 23 deletions.
3 changes: 2 additions & 1 deletion cli/include/Index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Index : public Subcall {
public:
cxxopts::ParseResult parseArgs(int argc, char** argv) override;
void execute(const cxxopts::ParseResult& args) override;

};

#endif //GENOGROVE_INDEX_HPP
#endif //GENOGROVE_INDEX_HPP
5 changes: 5 additions & 0 deletions cli/include/Overlap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class Overlap : public Subcall {
public:
cxxopts::ParseResult parseArgs(int argc, char** argv) override;
void execute(const cxxopts::ParseResult& args) override;

// getter & setter
cxxopts::Options getOptions();
void setOptions(cxxopts::Options options);

};

#endif //GENOGROVE_OVERLAP_HPP
1 change: 1 addition & 0 deletions cli/include/Subcall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Subcall {
virtual cxxopts::ParseResult parseArgs(int argc, char** argv) = 0;
virtual void execute(const cxxopts::ParseResult& args) = 0;
virtual ~Subcall() = default;

};

#endif //GENOGROVE_SUBCALL_HPP
14 changes: 11 additions & 3 deletions cli/src/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ cxxopts::ParseResult Index::parseArgs(int argc, char** argv) {
options.add_options()
("inputfile", "The input file to be indexed",
cxxopts::value<std::string>())
("-o, outputfile", "Write the index to the specified file",
("o, outputfile", "Write the index to the specified file",
cxxopts::value<std::string>())
("k, order", "The order of the tree (default: 3)",
cxxopts::value<int>()->default_value("3"))
("h, help", "Print help")

;
options.parse_positional({"inputfile"});
return options.parse(argc, argv);
cxxopts::ParseResult args = options.parse(argc, argv);

if(args.count("help")) {
options.help();
}
return args;
}


void Index::execute(const cxxopts::ParseResult& args) {
if(args.count("inputfile")) {
std::string inputfile = args["inputfile"].as<std::string>();
Expand All @@ -24,4 +32,4 @@ void Index::execute(const cxxopts::ParseResult& args) {
std::string outputfile = args["outputfile"].as<std::string>();
std::cout << "Writing index to file: " << outputfile << std::endl;
}
}
}
29 changes: 16 additions & 13 deletions cli/src/Overlap.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#include "Overlap.hpp"

cxxopts::ParseResult Overlap::parseArgs(int argc, char** argv) {
cxxopts::Options options("overlap", "Search for interval overlaps in the index");
cxxopts::Options options("index", "Index an Interval File");
options.add_options()
("input", "The search string or file to search for",
cxxopts::value<std::string>())
("o, output", "The output file to store the overlaps",
cxxopts::value<std::string>())
("inputfile", "The input file to be indexed",
cxxopts::value<std::string>())
("-o, outputfile", "Write the index to the specified file",
cxxopts::value<std::string>()->default_value(""))
("k, order", "The order of the tree (default: 3)",
cxxopts::value<int>()->default_value("3"))
;
options.parse_positional({"input"});
options.parse_positional({"inputfile"});
return options.parse(argc, argv);
}


void Overlap::execute(const cxxopts::ParseResult& args) {
if(args.count("input")) {
std::string input = args["input"].as<std::string>();
std::cout << "Searching for overlaps in file: " << input << std::endl;
if(args.count("inputfile")) {
std::string inputfile = args["inputfile"].as<std::string>();
std::cout << "Indexing file: " << inputfile << std::endl;
}

if(args.count("output")) {
std::string output = args["output"].as<std::string>();
std::cout << "Writing overlaps to file: " << output << std::endl;
if(args.count("outputfile")) {
std::string outputfile = args["outputfile"].as<std::string>();
std::cout << "Writing index to file: " << outputfile << std::endl;
}
}
}
8 changes: 2 additions & 6 deletions cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ int main(int argc, char** argv) {
}

// parse additional options for the subcommand
auto subcallArgs = command->parseArgs(argc, argv);
if(subcallArgs.count("help")) {

command->printHelp(options);
return 0;
}
cxxopts::ParseResult subcallArgs = command->parseArgs(argc, argv);
command->execute(subcallArgs);
}

0 comments on commit 505b909

Please sign in to comment.