fix very stupid out of range error
This commit is contained in:
@@ -39,7 +39,7 @@ namespace sym {
|
||||
const std::string arrow = "";
|
||||
}
|
||||
class col {
|
||||
public:
|
||||
public:
|
||||
col() { m_isres = true; }
|
||||
col(bool fg, unsigned char r, unsigned char g, unsigned char b) {
|
||||
m_isres = false;
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
return buf;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
bool m_isres = true;
|
||||
bool m_fg = false;
|
||||
unsigned char m_r = 0;
|
||||
@@ -124,7 +124,7 @@ void PrintFancy(const std::vector<std::pair<std::string, col>> &e) {
|
||||
}
|
||||
}
|
||||
class command {
|
||||
public:
|
||||
public:
|
||||
using ArgumentList = std::vector<std::pair<std::string, std::string>>;
|
||||
using Function = std::function<void(const ArgumentList &)>;
|
||||
class sub {
|
||||
@@ -180,14 +180,14 @@ public:
|
||||
const std::string &GetDesc() const { return m_desc; }
|
||||
const std::vector<sub> &GetArgs() const { return m_sub; }
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string m_name;
|
||||
std::string m_desc;
|
||||
std::vector<sub> m_sub;
|
||||
Function m_fun;
|
||||
};
|
||||
class arg_mgr {
|
||||
public:
|
||||
public:
|
||||
arg_mgr() {}
|
||||
arg_mgr(char **args, int argc) { Parse(args, argc); }
|
||||
arg_mgr(int argc, char **args) { Parse(args, argc); }
|
||||
@@ -204,8 +204,7 @@ public:
|
||||
}
|
||||
|
||||
std::string GetArg(std::string w, std::string def = "") {
|
||||
if (!FindShort(m_args, w))
|
||||
return def;
|
||||
if (!FindShort(m_args, w)) return def;
|
||||
for (size_t i = 0; i < m_args.size() - 1; i++) {
|
||||
if (m_args[i] == std::string("-" + w)) {
|
||||
return m_args[i + 1];
|
||||
@@ -268,6 +267,7 @@ public:
|
||||
|
||||
void Execute() {
|
||||
command::ArgumentList arglist;
|
||||
if (m_args.size() > 1) {
|
||||
for (const auto &c : m_commands) {
|
||||
if (c.GetName() == m_args[1]) {
|
||||
for (const auto &j : c.GetArgs()) {
|
||||
@@ -291,12 +291,13 @@ public:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
PrintHelp("");
|
||||
}
|
||||
|
||||
void AddCommand(command cmd) { m_commands.push_back(cmd); }
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string app_name;
|
||||
std::string app_version;
|
||||
std::vector<std::string> m_args;
|
||||
|
||||
Reference in New Issue
Block a user