forked from Alepha/Alepha
It's mostly worked out, but there's a few odd corner cases, especially around the auto-gen of negation options. It also got me to start thinking about "is a required negatable option still required of its negation?" Similar questions revolve around requiring such options. I'm punting on these for now, but I think it makes sense to perhaps make those incompatible with such domains. Or to treat the two options as a shared-fate unit. But is `-O -o -O -o` a violation of exclusivity? If we wind up returning to the default state, have we actually passed that option, with respect to "requirement"? I have to think about that some more. A commit message isn't the best place to capture this, but I didn't want to lose this thought.
50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
static_assert( __cplusplus > 2020'99 );
|
|
|
|
#include "ProgramOptions.h"
|
|
|
|
#include <Alepha/Utility/evaluation_helpers.h>
|
|
|
|
namespace
|
|
{
|
|
using namespace Alepha::literals::option_literals;
|
|
using namespace std::literals::string_literals;
|
|
|
|
using namespace Alepha::Utility::exports::evaluation_helpers_m;
|
|
|
|
int optionA= 42;
|
|
std::optional< std::string > optionB;
|
|
|
|
bool optionC= false;
|
|
|
|
const Alepha::RequirementDomain need;
|
|
const Alepha::ExclusivityDomain block;
|
|
//const Alepha::detail::ProgramOptions_m::Domain< nil > need;
|
|
//const Alepha::detail::ProgramOptions_m::Domain< nil > block;
|
|
|
|
auto init= enroll <=[]
|
|
{
|
|
--"set-a"_option << need << optionA << "The option is an integer. !default!";
|
|
--"set-b"_option << block << optionB << "The option is a string, no defaults.";
|
|
--"set-c"_option << block << need << optionC << "This sets the 'C' flag.";
|
|
};
|
|
}
|
|
|
|
int
|
|
main( const int argcnt, const char *const *const argvec )
|
|
try
|
|
{
|
|
const auto args= Alepha::handleOptions( argcnt, argvec, { { 'c', "set-c" }, { 'C', "no-set-c" }, { 'D', "dump-color-env-var" },
|
|
{ 'L', "list-color-variables" }, } );
|
|
|
|
std::cout << "A is set to: " << optionA << std::endl;
|
|
std::cout << "B is set to: " << ( optionB.has_value() ? optionB.value() : "nullopt"s ) << std::endl;
|
|
std::cout << "C is set to: " << std::boolalpha << optionC << std::endl;
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
catch( const std::exception &ex )
|
|
{
|
|
std::cerr << "Error: " << ex.what() << std::endl;
|
|
return EXIT_FAILURE;
|
|
}
|