mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
Return default_arguments from operator& of two default_arguments
operator& should return combined values of the same type, not a new type (i.e. bool). This is much more verbose, but easier to reason about without implied conversion. Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
This commit is contained in:
parent
6a8b1318ec
commit
7cbc66f65b
@ -332,8 +332,11 @@ enum class default_arguments : unsigned int {
|
|||||||
all = help | version,
|
all = help | version,
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator& (const default_arguments &a, const default_arguments &b) {
|
inline default_arguments operator& (const default_arguments &a,
|
||||||
return static_cast<unsigned int>(a) & static_cast<unsigned int>(b);
|
const default_arguments &b) {
|
||||||
|
return static_cast<default_arguments>(
|
||||||
|
static_cast<std::underlying_type<default_arguments>::type>(a) &
|
||||||
|
static_cast<std::underlying_type<default_arguments>::type>(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
class ArgumentParser;
|
class ArgumentParser;
|
||||||
@ -857,7 +860,7 @@ public:
|
|||||||
std::string aVersion = "1.0",
|
std::string aVersion = "1.0",
|
||||||
default_arguments aArgs = default_arguments::all)
|
default_arguments aArgs = default_arguments::all)
|
||||||
: mProgramName(std::move(aProgramName)), mVersion(std::move(aVersion)) {
|
: mProgramName(std::move(aProgramName)), mVersion(std::move(aVersion)) {
|
||||||
if (aArgs & default_arguments::help) {
|
if ((aArgs & default_arguments::help) == default_arguments::help) {
|
||||||
add_argument("-h", "--help")
|
add_argument("-h", "--help")
|
||||||
.action([&](const auto &) {
|
.action([&](const auto &) {
|
||||||
std::cout << help().str();
|
std::cout << help().str();
|
||||||
@ -868,7 +871,7 @@ public:
|
|||||||
.implicit_value(true)
|
.implicit_value(true)
|
||||||
.nargs(0);
|
.nargs(0);
|
||||||
}
|
}
|
||||||
if (aArgs & default_arguments::version) {
|
if ((aArgs & default_arguments::version) == default_arguments::version) {
|
||||||
add_argument("-v", "--version")
|
add_argument("-v", "--version")
|
||||||
.action([&](const auto &) {
|
.action([&](const auto &) {
|
||||||
std::cout << mVersion;
|
std::cout << mVersion;
|
||||||
|
Loading…
Reference in New Issue
Block a user