1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-08 07:43:52 +00:00

Adding ini print and simple tests

This commit is contained in:
Henry Fredrick Schreiner 2017-02-13 18:37:17 -05:00
parent 15c6ee5f3d
commit 4e69e9794d
3 changed files with 46 additions and 1 deletions

View File

@ -2,7 +2,9 @@
* Updates to help print
* 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

View File

@ -100,6 +100,15 @@ public:
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
App* add_subcommand(std::string name, std::string description="", bool help=true) {

View File

@ -2,6 +2,9 @@
#include <cstdio>
#include <sstream>
#include "gmock/gmock.h"
using ::testing::HasSubstr;
TEST(StringBased, First) {
std::stringstream ofile;
@ -134,3 +137,34 @@ TEST_F(TApp, IniRequired) {
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="));
}