Skip to content
Snippets Groups Projects
Commit 1314649d authored by Recolic Keghart's avatar Recolic Keghart
Browse files

tiny update. opt::getCommand interface update

parent 50f75532
No related branches found
No related tags found
No related merge requests found
......@@ -28,8 +28,8 @@ install_cmake: install_library
install: install_header install_library install_cmake
uninstall:
rm -rf $(PREFIX)/include/rlib
rm $(PREFIX)/lib/libr.a
rm -rf $(PREFIX)/include/rlib $(PREFIX)/lib/cmake/rlib
rm -f $(PREFIX)/lib/libr.a
clean:
rm *.o *.a
......@@ -31,6 +31,8 @@ namespace rlib {
friend class traceable_list;
public:
using pointer = T *;
using reference = T &;
explicit iterator(node *ptr) : ptr(ptr) {}
explicit iterator(T *data_pointer) : ptr(reinterpret_cast<node *>(data_pointer)) {
......
......@@ -25,16 +25,33 @@ namespace rlib {
public:
opt_parser() = delete;
opt_parser(size_t arglen, char **argv) {
if(argv[0] == nullptr)
throw std::runtime_error("Invalid argv passed to rlib::opt_parser. argv[0] is nullptr.");
arg0 = argv[0];
for(size_t cter = 1; cter < arglen; ++cter)
args.push_back(std::string(argv[cter]));
}
rlib::string getCommand() {
rlib::string getSubCommand() {
if(args.empty())
throw std::runtime_error("No sub-command available.");
auto cmd = std::move(args[0]);
args.erase(args.begin());
return std::move(cmd);
}
rlib::string getSubCommand(const std::string &def) {
if(args.empty())
return def;
auto cmd = std::move(args[0]);
args.erase(args.begin());
return std::move(cmd);
}
rlib::string getSelf() {
return arg0;
}
rlib::string getValueArg(const std::string &argName, bool required = true, const std::string &def = std::string())
{ //If required argument not exist, I'll throw. Else, return "" if arg is not read.
using rlib::literals::operator "" _format;
......@@ -102,6 +119,7 @@ namespace rlib {
}
private:
std::vector<std::string> args;
std::string arg0;
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment