mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 20:23:55 +00:00
* add expanded type_size specification * add some more checks for type_size_max * continued work on getting type sizes more flexible * make some more tweaks to option to split up validate and reduce sections * git rid of exceptions on the type_size functions exceptions, allow any number to be entered for the min and max and don't make a distinction between flags and other types. * add expected count * add the allow extra args flag in an option * start working in allow_extra_args * write some stuff in the book, and continue working on the failing test cases * fix a few more of the helpers tests * a few more test cases running * all tests pass, fixing calls in ini files * get vector<pair> working and all tests passing * change callback to use reference to remove allocation and copy operation * add support and test for vector<vector<X>> * change Validators_ to validators_ for consistency * fix linux warnings and errors by reording some templates and adding some typename keywords * add support for std::vector<X> as the cross conversion type so optional<std::vector<X>> is supported using the full template of add_option. * a few more test cases to take care of some coverage gaps * add missing parenthesis * add some more tests for coverage gaps * add test for flag like option * add transform test for `as<X>` function and make it pass through the defaults * add a few more tests and have vector default string interpreted correctly. * add test for defaulted integer, and route default string for defaulted value which would otherwise be empty * some code cleanup and comments and few more test coverage gap tests * add more tests and fix a few bugs on the type size and different code paths * remove path in results by fixing the clear of options so they go back to parsing state. * get coverage back to 100% * clang_tidy, and codacy fixes * reorder the lexical_conversion definitions * update some formatting * update whitespace on book chapter
58 lines
1.2 KiB
C++
58 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#ifdef CLI11_SINGLE_FILE
|
|
#include "CLI11.hpp"
|
|
#else
|
|
#include "CLI/CLI.hpp"
|
|
#endif
|
|
|
|
#include "gtest/gtest.h"
|
|
#include <iostream>
|
|
|
|
using input_t = std::vector<std::string>;
|
|
|
|
struct TApp : public ::testing::Test {
|
|
CLI::App app{"My Test Program"};
|
|
input_t args;
|
|
|
|
void run() {
|
|
// It is okay to re-parse - clear is called automatically before a parse.
|
|
input_t newargs = args;
|
|
std::reverse(std::begin(newargs), std::end(newargs));
|
|
app.parse(newargs);
|
|
}
|
|
};
|
|
|
|
class TempFile {
|
|
std::string _name;
|
|
|
|
public:
|
|
explicit TempFile(std::string name) : _name(std::move(name)) {
|
|
if(!CLI::NonexistentPath(_name).empty())
|
|
throw std::runtime_error(_name);
|
|
}
|
|
|
|
~TempFile() {
|
|
std::remove(_name.c_str()); // Doesn't matter if returns 0 or not
|
|
}
|
|
|
|
operator const std::string &() const { return _name; }
|
|
const char *c_str() const { return _name.c_str(); }
|
|
};
|
|
|
|
inline void put_env(std::string name, std::string value) {
|
|
#ifdef _WIN32
|
|
_putenv_s(name.c_str(), value.c_str());
|
|
#else
|
|
setenv(name.c_str(), value.c_str(), 1);
|
|
#endif
|
|
}
|
|
|
|
inline void unset_env(std::string name) {
|
|
#ifdef _WIN32
|
|
_putenv_s(name.c_str(), "");
|
|
#else
|
|
unsetenv(name.c_str());
|
|
#endif
|
|
}
|