mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-08 15:53:51 +00:00
Adding ini print and simple tests
This commit is contained in:
parent
15c6ee5f3d
commit
4e69e9794d
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
* Updates to help print
|
* Updates to help print
|
||||||
* Removed `run`, please use `parse` unless you subclass and add it
|
* Removed `run`, please use `parse` unless you subclass and add it
|
||||||
* Supports ini files mixed with command line
|
* Supports ini files mixed with command line, tested
|
||||||
|
* Added Range for further Plumbum compatibility
|
||||||
|
* Added function to print out ini file
|
||||||
|
|
||||||
## Version 0.3
|
## Version 0.3
|
||||||
|
|
||||||
|
@ -100,6 +100,15 @@ public:
|
|||||||
return ini_setting;
|
return ini_setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Produce a string that could be read in as a config of the current values of the App
|
||||||
|
std::string config_to_str() const {
|
||||||
|
std::stringstream out;
|
||||||
|
for(const Option_p &opt : options) {
|
||||||
|
if(opt->lnames.size() > 0 && opt->count() > 0)
|
||||||
|
out << opt->lnames[0] << "=" << detail::join(opt->flatten_results()) << std::endl;
|
||||||
|
}
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
/// Add a subcommand. Like the constructor, you can override the help message addition by setting help=false
|
/// Add a subcommand. Like the constructor, you can override the help message addition by setting help=false
|
||||||
App* add_subcommand(std::string name, std::string description="", bool help=true) {
|
App* add_subcommand(std::string name, std::string description="", bool help=true) {
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
|
using ::testing::HasSubstr;
|
||||||
|
|
||||||
TEST(StringBased, First) {
|
TEST(StringBased, First) {
|
||||||
std::stringstream ofile;
|
std::stringstream ofile;
|
||||||
@ -134,3 +137,34 @@ TEST_F(TApp, IniRequired) {
|
|||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
EXPECT_THROW(run(), CLI::RequiredError);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TApp, IniOutputSimple) {
|
||||||
|
|
||||||
|
int v;
|
||||||
|
app.add_option("--simple", v);
|
||||||
|
|
||||||
|
args = {"--simple=3"};
|
||||||
|
|
||||||
|
run();
|
||||||
|
|
||||||
|
std::string str = app.config_to_str();
|
||||||
|
EXPECT_EQ("simple=3\n", str);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST_F(TApp, IniOutputFlag) {
|
||||||
|
|
||||||
|
int v;
|
||||||
|
app.add_option("--simple", v);
|
||||||
|
app.add_flag("--nothing");
|
||||||
|
|
||||||
|
args = {"--simple=3", "--nothing"};
|
||||||
|
|
||||||
|
run();
|
||||||
|
|
||||||
|
std::string str = app.config_to_str();
|
||||||
|
EXPECT_THAT(str, HasSubstr("simple=3"));
|
||||||
|
EXPECT_THAT(str, HasSubstr("nothing="));
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user