Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions include/argparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ namespace argparse

enum class Handle
{
errors_and_help,
errors,
help,
none
none = 0,
errors = 1,
help = 2,
errors_and_help = errors | help
};

class parsing_error
Expand All @@ -63,6 +63,11 @@ namespace argparse
using runtime_error::runtime_error;
};

inline auto operator&(Handle lhs, Handle rhs) -> int
{
return static_cast<int>(lhs) & static_cast<int>(rhs);
}

inline auto from_string(std::string const & s, auto & t) -> bool
{
auto iss = std::istringstream(s);
Expand Down Expand Up @@ -170,7 +175,7 @@ namespace argparse
}
catch (HelpRequested const &)
{
if (m_handle == Handle::errors_and_help || m_handle == Handle::help)
if (m_handle & Handle::help)
{
std::cout << format_help() << std::endl;
std::exit(EXIT_SUCCESS);
Expand All @@ -180,7 +185,7 @@ namespace argparse
}
catch (VersionRequested const &)
{
if (m_handle == Handle::errors_and_help || m_handle == Handle::help)
if (m_handle & Handle::help)
{
std::cout << format_version() << std::endl;
std::exit(EXIT_SUCCESS);
Expand All @@ -190,7 +195,7 @@ namespace argparse
}
catch (parsing_error const & e)
{
if (m_handle == Handle::errors_and_help || m_handle == Handle::errors)
if (m_handle & Handle::errors)
{
std::cout << e.what() << '\n';
std::cout << format_help() << std::endl;
Expand Down