Skip to content

Commit adf201e

Browse files
committed
remove version calls and tests
1 parent 318e0f7 commit adf201e

File tree

3 files changed

+18
-56
lines changed

3 files changed

+18
-56
lines changed

examples/simple.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ int main(int argc, char **argv) {
1212

1313
CLI::App app("K3Pi goofit fitter");
1414
// add version output
15-
app.version(std::string(CLI11_VERSION));
16-
15+
app.set_version_flag("--version",std::string(CLI11_VERSION));
1716
std::string file;
1817
CLI::Option *opt = app.add_option("-f,--file,file", file, "File name");
1918

include/CLI/App.hpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -744,17 +744,6 @@ class App {
744744

745745
return version_ptr_;
746746
}
747-
/// Set the version as a string
748-
App *version(const std::string &versionString) {
749-
set_version_flag("--version", versionString);
750-
return this;
751-
}
752-
753-
/// Generate the version string through a callback function
754-
App *version(std::function<std::string()> vfunc) {
755-
set_version_flag("--version", vfunc);
756-
return this;
757-
}
758747

759748
private:
760749
/// Internal function for adding a flag
@@ -1588,23 +1577,6 @@ class App {
15881577
return formatter_->make_help(this, prev, mode);
15891578
}
15901579

1591-
/// Displays a version string
1592-
std::string version() const {
1593-
std::string val;
1594-
if(version_ptr_ != nullptr) {
1595-
auto rv = version_ptr_->results();
1596-
version_ptr_->clear();
1597-
version_ptr_->add_result("true");
1598-
try {
1599-
version_ptr_->run_callback();
1600-
} catch(const CLI::CallForVersion &cfv) {
1601-
val = cfv.what();
1602-
}
1603-
version_ptr_->clear();
1604-
version_ptr_->add_result(rv);
1605-
}
1606-
return val;
1607-
}
16081580
///@}
16091581
/// @name Getters
16101582
///@{

tests/HelpTest.cpp

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,17 +1166,28 @@ TEST(THelp, FunctionDefaultString) {
11661166
EXPECT_THAT(help, HasSubstr("INT=Powerful"));
11671167
}
11681168

1169+
static std::string getVersion(CLI::App& app, const std::string &args="--version")
1170+
{
1171+
try {
1172+
app.parse(args);
1173+
}
1174+
catch (const CLI::CallForVersion& v)
1175+
{
1176+
return v.what();
1177+
}
1178+
return std::string{};
1179+
}
11691180
TEST(TVersion, simple_flag) {
11701181

11711182
CLI::App app;
11721183

11731184
app.set_version_flag("-v,--version", "VERSION " CLI11_VERSION);
11741185

1175-
auto vers = app.version();
1186+
auto vers = getVersion(app);
11761187
EXPECT_THAT(vers, HasSubstr("VERSION"));
1177-
1188+
app.allow_extras();
11781189
app.set_version_flag();
1179-
EXPECT_TRUE(app.version().empty());
1190+
EXPECT_TRUE(getVersion(app).empty());
11801191
}
11811192

11821193
TEST(TVersion, callback_flag) {
@@ -1185,39 +1196,19 @@ TEST(TVersion, callback_flag) {
11851196

11861197
app.set_version_flag("-v,--version", []() { return std::string("VERSION " CLI11_VERSION); });
11871198

1188-
auto vers = app.version();
1199+
auto vers = getVersion(app);
11891200
EXPECT_THAT(vers, HasSubstr("VERSION"));
11901201

11911202
app.set_version_flag("-v", []() { return std::string("VERSION2 " CLI11_VERSION); });
1192-
vers = app.version();
1193-
EXPECT_THAT(vers, HasSubstr("VERSION"));
1194-
}
1195-
1196-
TEST(TVersion, simple_direct) {
1197-
1198-
CLI::App app;
1199-
1200-
app.version(std::string("VERSION " CLI11_VERSION));
1201-
1202-
auto vers = app.version();
1203-
EXPECT_THAT(vers, HasSubstr("VERSION"));
1204-
}
1205-
1206-
TEST(TVersion, callback_direct) {
1207-
1208-
CLI::App app;
1209-
1210-
app.version([]() { return std::string("VERSION " CLI11_VERSION); });
1211-
1212-
auto vers = app.version();
1203+
vers = getVersion(app,"-v");
12131204
EXPECT_THAT(vers, HasSubstr("VERSION"));
12141205
}
12151206

12161207
TEST(TVersion, parse_throw) {
12171208

12181209
CLI::App app;
12191210

1220-
app.version(CLI11_VERSION);
1211+
app.set_version_flag("--version", CLI11_VERSION);
12211212

12221213
EXPECT_THROW(app.parse("--version"), CLI::CallForVersion);
12231214
EXPECT_THROW(app.parse("--version --arg2 5"), CLI::CallForVersion);

0 commit comments

Comments
 (0)