fix(basen): basen::Exception
This commit is contained in:
@ -41,7 +41,7 @@ namespace basen
|
||||
if (isatty(fileno(stdin)))
|
||||
#endif
|
||||
{
|
||||
throw std::logic_error("basen::getPipe: should use pipe syntax");
|
||||
throw std::logic_error("should use pipe syntax ( | or < )");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -60,8 +60,9 @@ namespace basen
|
||||
}
|
||||
uint8_t error(const std::string &str, argparse::ArgumentParser &program) noexcept
|
||||
{
|
||||
std::cerr << str << '\n';
|
||||
std::cerr << program << '\n';
|
||||
std::cerr << "\033[31merror:\t\033[0m"
|
||||
<< str << "\n\n"
|
||||
<< program << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -102,8 +103,10 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
return basen::error("should use pipe syntax ( | or < )", program);
|
||||
return basen::error(e.what(), program);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (program.is_used("-t"))
|
||||
{
|
||||
auto type = program.get<std::string>("-t");
|
||||
@ -124,14 +127,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
auto alphabet = program.get<std::string>("-a");
|
||||
uint8_t map[256];
|
||||
try
|
||||
{
|
||||
baseN::digitsMap(alphabet.data(), alphabet.size(), map);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
return basen::error("alphabet contains same characters", program);
|
||||
}
|
||||
if (program.is_used("-d"))
|
||||
{
|
||||
auto data = baseN::decode(str, alphabet.size(), alphabet.data(), map);
|
||||
@ -145,5 +141,10 @@ int main(int argc, char *argv[])
|
||||
std::cout << baseN::encode(dv, alphabet.size(), alphabet.data()) << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const basen::Exception &e)
|
||||
{
|
||||
return basen::error(e.message(), program);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user