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