Skip to content

Commit

Permalink
allow bool arguments without a sink variable
Browse files Browse the repository at this point in the history
  • Loading branch information
MikkelSchubert committed Jul 28, 2024
1 parent 078a5b6 commit 9fd6d5d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/argparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,8 @@ sink::preprocess(std::string value) const

bool_sink::bool_sink(bool* ptr)
: sink(0)
, m_sink(ptr)
, m_sink(ptr ? ptr : &m_fallback_sink)
{
AR_REQUIRE(ptr);

*m_sink = false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ class bool_sink : public sink

private:
bool* m_sink;
//! Sink variable used if no sink was supplied
bool m_fallback_sink = false;
};

class uint_sink : public sink
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/argparse_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ using Catch::Matchers::Contains;
///////////////////////////////////////////////////////////////////////////////
// boolean sink

TEST_CASE("bool sink is required", "[argparse::bool_sink]")
{
REQUIRE_THROWS_AS(argparse::bool_sink(nullptr), assert_failed);
}

TEST_CASE("bool sink is initialized", "[argparse::bool_sink]")
{
bool value = true;
Expand Down

0 comments on commit 9fd6d5d

Please sign in to comment.