Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed update to remove RAII problem #251

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 9 additions & 2 deletions include/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,13 @@ class Argument {
std::string_view m_prefix_chars; // ArgumentParser has the prefix_chars
};

class NormalProgramTermination : public std::exception {
public:
const char * what () {
return "Normal program termination is expected";
}
};

class ArgumentParser {
public:
explicit ArgumentParser(std::string program_name = {},
Expand All @@ -1052,7 +1059,7 @@ class ArgumentParser {
add_argument("-h", "--help")
.action([&](const auto & /*unused*/) {
std::cout << help().str();
std::exit(0);
throw NormalProgramTermination();
})
.default_value(false)
.help("shows help message and exits")
Expand All @@ -1063,7 +1070,7 @@ class ArgumentParser {
add_argument("-v", "--version")
.action([&](const auto & /*unused*/) {
std::cout << m_version << std::endl;
std::exit(0);
throw NormalProgramTermination();
})
.default_value(false)
.help("prints version information and exits")
Expand Down