mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 12:43:52 +00:00
This has been bounced around for a couple years now #474 and a few others have expressed desire to work with non-standard option names. We have been somewhat resistant to that but I think it can be done now. This PR adds a modifier `allow_non_standard_option_names()` It is purposely long, it is purposely off by default. But what it does is allow option names with a single `-` to act like a short option name. With this modifier enabled no single letter short option names are allowed to start with the same letter as a non-standard names. For example `-s` and `-single` would not be allowed. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
// Copyright (c) 2017-2024, University of Cincinnati, developed by Henry Schreiner
|
|
// under NSF AWARD 1414736 and by the respective contributors.
|
|
// All rights reserved.
|
|
//
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// from Issue #566 on github https://github.com/CLIUtils/CLI11/issues/566
|
|
|
|
#include <CLI/CLI.hpp>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
// example file to demonstrate a custom lexical cast function
|
|
|
|
template <class T = int> struct Values {
|
|
T a;
|
|
T b;
|
|
T c;
|
|
};
|
|
|
|
// in C++20 this is constructible from a double due to the new aggregate initialization in C++20.
|
|
using DoubleValues = Values<double>;
|
|
|
|
// the lexical cast operator should be in the same namespace as the type for ADL to work properly
|
|
bool lexical_cast(const std::string &input, Values<double> & /*v*/) {
|
|
std::cout << "called correct lexical_cast function ! val: " << input << '\n';
|
|
return true;
|
|
}
|
|
|
|
DoubleValues doubles;
|
|
void argparse(CLI::Option_group *group) { group->add_option("--dv", doubles)->default_str("0"); }
|
|
|
|
int main(int argc, char **argv) {
|
|
CLI::App app;
|
|
|
|
argparse(app.add_option_group("param"));
|
|
CLI11_PARSE(app, argc, argv);
|
|
return 0;
|
|
}
|