zdzhaoyong / Svar

A Tiny Modern C++ Header Brings Unified Interface for Different Languages
Other
149 stars 17 forks source link

Argument parse error #12

Closed xiaodaxia-2008 closed 2 years ago

xiaodaxia-2008 commented 2 years ago

If adding an int type argument and given a negative number, it cannot work as expected.

#include <fmt/format.h>
#include <Svar/Svar.h>

int main(int argc, char **argv)
{
    svar.parseMain(argc, argv);
    svar.arg<int>("n", 1, "int number");
    if (svar.get<bool>("help", false))
    {
        return svar.help();
    }

    int n = svar.get<int>("n", 1);
    fmt::print("n is {}\n", n);
    return 0;
}

If call with -n -5,it seems to parse -5 as another argument name, but not the number that representing n. And it works well for number >= 0.

➜ build ./bin/main -n -5 n is 1

zdzhaoyong commented 2 years ago

Yes it is a kown issue, now it is fixed in pull #13 , thanks for the issue reporting.