Commit e2e3cb2fed20b0c25eaf6d2689784b9c0e3730f1

Authored by Henry Schreiner
Committed by GitHub
1 parent 6ca5df87

refactor!: drop defaulted from add_option (#597)

CHANGELOG.md
... ... @@ -15,10 +15,15 @@
15 15 * Bugfix: avoid listing helpall as a required flag [#530][]
16 16 * Bugfix: avoid a clash with WINDOWS define [#563][]
17 17  
18   -* Removed deprecated set commands, use validators instead. [#565][]
19   -
20 18 * Build: support pkg-config [#523][]
21 19  
  20 +#### Converting from CLI11 1.9:
  21 +
  22 +* Removed deprecated set commands, use validators instead. [#565][]
  23 +* The final "defaulted" bool has been removed, use `->capture_default_str()`
  24 + instead. Use `app.option_defaults()->always_capture_default()` to set this for
  25 + all future options. [#597][]
  26 +
22 27  
23 28 [#435]: https://github.com/CLIUtils/CLI11/pull/435
24 29 [#443]: https://github.com/CLIUtils/CLI11/pull/443
... ... @@ -35,6 +40,7 @@
35 40 [#563]: https://github.com/CLIUtils/CLI11/pull/563
36 41 [#565]: https://github.com/CLIUtils/CLI11/pull/565
37 42 [#574]: https://github.com/CLIUtils/CLI11/pull/574
  43 +[#597]: https://github.com/CLIUtils/CLI11/pull/597
38 44  
39 45  
40 46  
... ... @@ -136,6 +142,7 @@ configuration options were added to facilitate a wider variety of apps. GCC
136 142 [#360]: https://github.com/CLIUtils/CLI11/pull/360
137 143 [#362]: https://github.com/CLIUtils/CLI11/pull/362
138 144 [#365]: https://github.com/CLIUtils/CLI11/pull/365
  145 +[#370]: https://github.com/CLIUtils/CLI11/pull/370
139 146 [#373]: https://github.com/CLIUtils/CLI11/pull/373
140 147 [#374]: https://github.com/CLIUtils/CLI11/pull/374
141 148 [#382]: https://github.com/CLIUtils/CLI11/pull/382
... ...
book/chapters/options.md
... ... @@ -9,11 +9,11 @@ int int_option{0};
9 9 app.add_option("-i", int_option, "Optional description");
10 10 ```
11 11  
12   -This will bind the option `-i` to the integer `int_option`. On the command line, a single value that can be converted to an integer will be expected. Non-integer results will fail. If that option is not given, CLI11 will not touch the initial value. This allows you to set up defaults by simply setting your value beforehand. If you want CLI11 to display your default value, you can add the optional final argument `true` when you add the option.
  12 +This will bind the option `-i` to the integer `int_option`. On the command line, a single value that can be converted to an integer will be expected. Non-integer results will fail. If that option is not given, CLI11 will not touch the initial value. This allows you to set up defaults by simply setting your value beforehand. If you want CLI11 to display your default value, you can add `->capture_default_str()` after the option.
13 13  
14 14 ```cpp
15 15 int int_option{0};
16   -app.add_option("-i", int_option, "Optional description", true);
  16 +app.add_option("-i", int_option, "Optional description")->capture_default_str();
17 17 ```
18 18  
19 19 You can use any C++ int-like type, not just `int`. CLI11 understands the following categories of types:
... ...
examples/nested.cpp
... ... @@ -18,7 +18,9 @@ int main(int argc, char **argv) {
18 18  
19 19 std::string mvcamera_config_file = "mvcamera_config.json";
20 20 CLI::App *mvcameraApp = cameraApp->add_subcommand("mvcamera", "MatrixVision Camera Configuration");
21   - mvcameraApp->add_option("-c,--config", mvcamera_config_file, "Config filename", true)->check(CLI::ExistingFile);
  21 + mvcameraApp->add_option("-c,--config", mvcamera_config_file, "Config filename")
  22 + ->capture_default_str()
  23 + ->check(CLI::ExistingFile);
22 24  
23 25 std::string mock_camera_path;
24 26 CLI::App *mockcameraApp = cameraApp->add_subcommand("mock", "Mock Camera Configuration");
... ...
examples/ranges.cpp
... ... @@ -19,7 +19,7 @@ int main(int argc, char **argv) {
19 19 int min{0}, max{0}, step{1};
20 20 ogroup->add_option("--min,-m", min, "The minimum")->required();
21 21 ogroup->add_option("--max,-M", max, "The maximum")->required();
22   - ogroup->add_option("--step,-s", step, "The step", true);
  22 + ogroup->add_option("--step,-s", step, "The step")->capture_default_str();
23 23  
24 24 app.require_option(1);
25 25  
... ...
include/CLI/App.hpp
... ... @@ -611,14 +611,13 @@ class App {
611 611 enable_if_t<!std::is_const<ConvertTo>::value, detail::enabler> = detail::dummy>
612 612 Option *add_option(std::string option_name,
613 613 AssignTo &variable, ///< The variable to set
614   - std::string option_description = "",
615   - bool defaulted = false) {
  614 + std::string option_description = "") {
616 615  
617 616 auto fun = [&variable](const CLI::results_t &res) { // comment for spacing
618 617 return detail::lexical_conversion<AssignTo, ConvertTo>(res, variable);
619 618 };
620 619  
621   - Option *opt = add_option(option_name, fun, option_description, defaulted, [&variable]() {
  620 + Option *opt = add_option(option_name, fun, option_description, false, [&variable]() {
622 621 return CLI::detail::checked_to_string<AssignTo, ConvertTo>(variable);
623 622 });
624 623 opt->type_name(detail::type_name<ConvertTo>());
... ...
test_package/example.cpp
... ... @@ -9,7 +9,7 @@ int main(int argc, char **argv) {
9 9 CLI::App app("Some nice description");
10 10  
11 11 int x = 0;
12   - app.add_option("-x", x, "an integer value", true /* show default */);
  12 + app.add_option("-x", x, "an integer value")->capture_default_str();
13 13  
14 14 bool flag;
15 15 app.add_flag("-f,--flag", flag, "a flag option");
... ...
tests/AppTest.cpp
... ... @@ -2219,7 +2219,7 @@ TEST_CASE_METHOD(TApp, &quot;CustomUserSepParse3&quot;, &quot;[app]&quot;) {
2219 2219 CHECK(std::vector<int>({1, 2}) == vals);
2220 2220 app.remove_option(opt);
2221 2221  
2222   - app.add_option("--idx", vals, "", false)->delimiter(',');
  2222 + app.add_option("--idx", vals)->delimiter(',');
2223 2223 run();
2224 2224 CHECK(std::vector<int>({1, 2}) == vals);
2225 2225 }
... ...
tests/ConfigFileTest.cpp
... ... @@ -1685,7 +1685,7 @@ TEST_CASE_METHOD(TApp, &quot;TomlOutputHiddenOptions&quot;, &quot;[config]&quot;) {
1685 1685 const std::string description2 = "Second description.";
1686 1686 app.add_flag("--" + flag1, description1)->group("group1");
1687 1687 app.add_flag("--" + flag2, description2)->group("group2");
1688   - app.add_option("--dval", val, "", true)->group("");
  1688 + app.add_option("--dval", val)->capture_default_str()->group("");
1689 1689  
1690 1690 run();
1691 1691  
... ... @@ -1723,7 +1723,7 @@ TEST_CASE_METHOD(TApp, &quot;TomlOutputOptionGroup&quot;, &quot;[config]&quot;) {
1723 1723 app.add_flag("--" + flag1, description1)->group("group1");
1724 1724 app.add_flag("--" + flag2, description2)->group("group2");
1725 1725 auto og = app.add_option_group("group3", "g3 desc");
1726   - og->add_option("--dval", val, "", true)->group("");
  1726 + og->add_option("--dval", val)->capture_default_str()->group("");
1727 1727  
1728 1728 run();
1729 1729  
... ... @@ -1809,7 +1809,7 @@ TEST_CASE_METHOD(TApp, &quot;TomlOutputSet&quot;, &quot;[config]&quot;) {
1809 1809 TEST_CASE_METHOD(TApp, "TomlOutputDefault", "[config]") {
1810 1810  
1811 1811 int v{7};
1812   - app.add_option("--simple", v, "", true);
  1812 + app.add_option("--simple", v)->capture_default_str();
1813 1813  
1814 1814 run();
1815 1815  
... ... @@ -1934,10 +1934,10 @@ TEST_CASE_METHOD(TApp, &quot;TomlOutputQuoted&quot;, &quot;[config]&quot;) {
1934 1934 TEST_CASE_METHOD(TApp, "DefaultsTomlOutputQuoted", "[config]") {
1935 1935  
1936 1936 std::string val1{"I am a string"};
1937   - app.add_option("--val1", val1, "", true);
  1937 + app.add_option("--val1", val1)->capture_default_str();
1938 1938  
1939 1939 std::string val2{R"(I am a "confusing" string)"};
1940   - app.add_option("--val2", val2, "", true);
  1940 + app.add_option("--val2", val2)->capture_default_str();
1941 1941  
1942 1942 run();
1943 1943  
... ... @@ -2068,7 +2068,7 @@ TEST_CASE_METHOD(TApp, &quot;IniOutputHiddenOptions&quot;, &quot;[config]&quot;) {
2068 2068 const std::string description2 = "Second description.";
2069 2069 app.add_flag("--" + flag1, description1)->group("group1");
2070 2070 app.add_flag("--" + flag2, description2)->group("group2");
2071   - app.add_option("--dval", val, "", true)->group("");
  2071 + app.add_option("--dval", val)->capture_default_str()->group("");
2072 2072 app.config_formatter(std::make_shared<CLI::ConfigINI>());
2073 2073 run();
2074 2074  
... ... @@ -2106,7 +2106,7 @@ TEST_CASE_METHOD(TApp, &quot;IniOutputOptionGroup&quot;, &quot;[config]&quot;) {
2106 2106 app.add_flag("--" + flag1, description1)->group("group1");
2107 2107 app.add_flag("--" + flag2, description2)->group("group2");
2108 2108 auto og = app.add_option_group("group3", "g3 desc");
2109   - og->add_option("--dval", val, "", true)->group("");
  2109 + og->add_option("--dval", val)->capture_default_str()->group("");
2110 2110 app.config_formatter(std::make_shared<CLI::ConfigINI>());
2111 2111 run();
2112 2112  
... ... @@ -2177,7 +2177,7 @@ TEST_CASE_METHOD(TApp, &quot;IniOutputSet&quot;, &quot;[config]&quot;) {
2177 2177 TEST_CASE_METHOD(TApp, "IniOutputDefault", "[config]") {
2178 2178  
2179 2179 int v{7};
2180   - app.add_option("--simple", v, "", true);
  2180 + app.add_option("--simple", v)->capture_default_str();
2181 2181 app.config_formatter(std::make_shared<CLI::ConfigINI>());
2182 2182 run();
2183 2183  
... ... @@ -2302,10 +2302,10 @@ TEST_CASE_METHOD(TApp, &quot;IniOutputQuoted&quot;, &quot;[config]&quot;) {
2302 2302 TEST_CASE_METHOD(TApp, "DefaultsIniOutputQuoted", "[config]") {
2303 2303  
2304 2304 std::string val1{"I am a string"};
2305   - app.add_option("--val1", val1, "", true);
  2305 + app.add_option("--val1", val1)->capture_default_str();
2306 2306  
2307 2307 std::string val2{R"(I am a "confusing" string)"};
2308   - app.add_option("--val2", val2, "", true);
  2308 + app.add_option("--val2", val2)->capture_default_str();
2309 2309 app.config_formatter(std::make_shared<CLI::ConfigINI>());
2310 2310 run();
2311 2311  
... ...
tests/CreationTest.cpp
... ... @@ -739,13 +739,13 @@ TEST_CASE_METHOD(TApp, &quot;MakeUnstreamableOptions&quot;, &quot;[creation]&quot;) {
739 739 app.add_option("--value", value);
740 740  
741 741 // This used to fail to build, since it tries to stream from Unstreamable
742   - app.add_option("--value2", value, "", false);
  742 + app.add_option("--value2", value);
743 743  
744 744 std::vector<Unstreamable> values;
745 745 app.add_option("--values", values);
746 746  
747 747 // This used to fail to build, since it tries to stream from Unstreamable
748   - app.add_option("--values2", values, "", false);
  748 + app.add_option("--values2", values);
749 749  
750 750 args = {"--value", "45"};
751 751 run();
... ...
tests/DeprecatedTest.cpp
... ... @@ -12,214 +12,3 @@ TEST_CASE(&quot;Deprecated: Empty&quot;, &quot;[deprecated]&quot;) {
12 12 // No deprecated features at this time.
13 13 CHECK(true);
14 14 }
15   -
16   -// Classic sets
17   -
18   -TEST_CASE("THelp: Defaults", "[deprecated]") {
19   - CLI::App app{"My prog"};
20   -
21   - int one{1}, two{2};
22   - app.add_option("--one", one, "Help for one", true);
23   - app.add_option("--set", two, "Help for set", true)->check(CLI::IsMember({2, 3, 4}));
24   -
25   - std::string help = app.help();
26   -
27   - CHECK_THAT(help, Contains("--one"));
28   - CHECK_THAT(help, Contains("--set"));
29   - CHECK_THAT(help, Contains("1"));
30   - CHECK_THAT(help, Contains("=2"));
31   - CHECK_THAT(help, Contains("2,3,4"));
32   -}
33   -
34   -TEST_CASE("THelp: VectorOpts", "[deprecated]") {
35   - CLI::App app{"My prog"};
36   - std::vector<int> x = {1, 2};
37   - app.add_option("-q,--quick", x, "", true);
38   -
39   - std::string help = app.help();
40   -
41   - CHECK_THAT(help, Contains("INT=[1,2] ..."));
42   -}
43   -
44   -TEST_CASE("THelp: SetLower", "[deprecated]") {
45   - CLI::App app{"My prog"};
46   -
47   - std::string def{"One"};
48   - app.add_option("--set", def, "Help for set", true)->check(CLI::IsMember({"oNe", "twO", "THREE"}));
49   -
50   - std::string help = app.help();
51   -
52   - CHECK_THAT(help, Contains("--set"));
53   - CHECK_THAT(help, Contains("=One"));
54   - CHECK_THAT(help, Contains("oNe"));
55   - CHECK_THAT(help, Contains("twO"));
56   - CHECK_THAT(help, Contains("THREE"));
57   -}
58   -
59   -TEST_CASE("THelp: ChangingSetDefaulted", "[deprecated]") {
60   - CLI::App app;
61   -
62   - std::set<int> vals{1, 2, 3};
63   - int val = 2;
64   - app.add_option("--val", val, "", true)->check(CLI::IsMember(&vals));
65   -
66   - std::string help = app.help();
67   -
68   - CHECK_THAT(help, Contains("1"));
69   - CHECK_THAT(help, !Contains("4"));
70   -
71   - vals.insert(4);
72   - vals.erase(1);
73   -
74   - help = app.help();
75   -
76   - CHECK_THAT(help, !Contains("1"));
77   - CHECK_THAT(help, Contains("4"));
78   -}
79   -
80   -TEST_CASE("THelp: ChangingCaselessSetDefaulted", "[deprecated]") {
81   - CLI::App app;
82   -
83   - std::set<std::string> vals{"1", "2", "3"};
84   - std::string val = "2";
85   - app.add_option("--val", val, "", true)->check(CLI::IsMember(&vals, CLI::ignore_case));
86   -
87   - std::string help = app.help();
88   -
89   - CHECK_THAT(help, Contains("1"));
90   - CHECK_THAT(help, !Contains("4"));
91   -
92   - vals.insert("4");
93   - vals.erase("1");
94   -
95   - help = app.help();
96   -
97   - CHECK_THAT(help, !Contains("1"));
98   - CHECK_THAT(help, Contains("4"));
99   -}
100   -
101   -TEST_CASE_METHOD(TApp, "DefaultOpts", "[deprecated]") {
102   -
103   - int i = 3;
104   - std::string s = "HI";
105   -
106   - app.add_option("-i,i", i, "", false);
107   - app.add_option("-s,s", s, "", true);
108   -
109   - args = {"-i2", "9"};
110   -
111   - run();
112   -
113   - CHECK(app.count("i") == 1u);
114   - CHECK(app.count("-s") == 1u);
115   - CHECK(i == 2);
116   - CHECK(s == "9");
117   -}
118   -
119   -TEST_CASE_METHOD(TApp, "VectorDefaultedFixedString", "[deprecated]") {
120   - std::vector<std::string> strvec{"one"};
121   - std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
122   -
123   - CLI::Option *opt = app.add_option("-s,--string", strvec, "", true)->expected(3);
124   - CHECK(opt->get_expected() == 3);
125   -
126   - args = {"--string", "mystring", "mystring2", "mystring3"};
127   - run();
128   - CHECK(app.count("--string") == 3u);
129   - CHECK(strvec == answer);
130   -}
131   -
132   -TEST_CASE_METHOD(TApp, "DefaultedResult", "[deprecated]") {
133   - std::string sval = "NA";
134   - int ival;
135   - auto opts = app.add_option("--string", sval, "", true);
136   - auto optv = app.add_option("--val", ival);
137   - args = {};
138   - run();
139   - CHECK("NA" == sval);
140   - std::string nString;
141   - opts->results(nString);
142   - CHECK("NA" == nString);
143   - int newIval;
144   - // CHECK_THROWS_AS (optv->results(newIval), CLI::ConversionError);
145   - optv->default_str("442");
146   - optv->results(newIval);
147   - CHECK(442 == newIval);
148   -}
149   -
150   -TEST_CASE_METHOD(TApp, "OptionWithDefaults", "[deprecated]") {
151   - int someint = 2;
152   - app.add_option("-a", someint, "", true);
153   -
154   - args = {"-a1", "-a2"};
155   -
156   - CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
157   -}
158   -
159   -// #209
160   -TEST_CASE_METHOD(TApp, "CustomUserSepParse", "[deprecated]") {
161   -
162   - std::vector<int> vals = {1, 2, 3};
163   - args = {"--idx", "1,2,3"};
164   - auto opt = app.add_option("--idx", vals)->delimiter(',');
165   - run();
166   - CHECK(std::vector<int>({1, 2, 3}) == vals);
167   - std::vector<int> vals2;
168   - // check that the results vector gets the results in the same way
169   - opt->results(vals2);
170   - CHECK(vals == vals2);
171   -
172   - app.remove_option(opt);
173   -
174   - app.add_option("--idx", vals, "", true)->delimiter(',');
175   - run();
176   - CHECK(std::vector<int>({1, 2, 3}) == vals);
177   -}
178   -
179   -// #209
180   -TEST_CASE_METHOD(TApp, "CustomUserSepParse2", "[deprecated]") {
181   -
182   - std::vector<int> vals = {1, 2, 3};
183   - args = {"--idx", "1,2,"};
184   - auto opt = app.add_option("--idx", vals)->delimiter(',');
185   - run();
186   - CHECK(std::vector<int>({1, 2}) == vals);
187   -
188   - app.remove_option(opt);
189   -
190   - app.add_option("--idx", vals, "", true)->delimiter(',');
191   - run();
192   - CHECK(std::vector<int>({1, 2}) == vals);
193   -}
194   -//
195   -// #209
196   -TEST_CASE_METHOD(TApp, "CustomUserSepParse4", "[deprecated]") {
197   -
198   - std::vector<int> vals;
199   - args = {"--idx", "1, 2"};
200   - auto opt = app.add_option("--idx", vals, "", true)->delimiter(',');
201   - run();
202   - CHECK(std::vector<int>({1, 2}) == vals);
203   -
204   - app.remove_option(opt);
205   -
206   - app.add_option("--idx", vals)->delimiter(',');
207   - run();
208   - CHECK(std::vector<int>({1, 2}) == vals);
209   -}
210   -
211   -// #218
212   -TEST_CASE_METHOD(TApp, "CustomUserSepParse5", "[deprecated]") {
213   -
214   - std::vector<std::string> bar;
215   - args = {"this", "is", "a", "test"};
216   - auto opt = app.add_option("bar", bar, "bar");
217   - run();
218   - CHECK(std::vector<std::string>({"this", "is", "a", "test"}) == bar);
219   -
220   - app.remove_option(opt);
221   - args = {"this", "is", "a", "test"};
222   - app.add_option("bar", bar, "bar", true);
223   - run();
224   - CHECK(std::vector<std::string>({"this", "is", "a", "test"}) == bar);
225   -}
... ...
tests/NewParseTest.cpp
... ... @@ -35,7 +35,7 @@ TEST_CASE_METHOD(TApp, &quot;Complex&quot;, &quot;[newparse]&quot;) {
35 35  
36 36 TEST_CASE_METHOD(TApp, "ComplexOption", "[newparse]") {
37 37 cx comp{1, 2};
38   - app.add_option("-c,--complex", comp, "", true);
  38 + app.add_option("-c,--complex", comp)->capture_default_str();
39 39  
40 40 args = {"-c", "4", "3"};
41 41  
... ... @@ -55,7 +55,7 @@ TEST_CASE_METHOD(TApp, &quot;ComplexOption&quot;, &quot;[newparse]&quot;) {
55 55  
56 56 TEST_CASE_METHOD(TApp, "ComplexFloat", "[newparse]") {
57 57 std::complex<float> comp{1, 2};
58   - app.add_complex<std::complex<float>, float>("-c,--complex", comp, "", true);
  58 + app.add_complex<std::complex<float>, float>("-c,--complex", comp)->capture_default_str();
59 59  
60 60 args = {"-c", "4", "3"};
61 61  
... ... @@ -75,7 +75,7 @@ TEST_CASE_METHOD(TApp, &quot;ComplexFloat&quot;, &quot;[newparse]&quot;) {
75 75  
76 76 TEST_CASE_METHOD(TApp, "ComplexFloatOption", "[newparse]") {
77 77 std::complex<float> comp{1, 2};
78   - app.add_option("-c,--complex", comp, "", true);
  78 + app.add_option("-c,--complex", comp)->capture_default_str();
79 79  
80 80 args = {"-c", "4", "3"};
81 81  
... ... @@ -95,7 +95,7 @@ TEST_CASE_METHOD(TApp, &quot;ComplexFloatOption&quot;, &quot;[newparse]&quot;) {
95 95  
96 96 TEST_CASE_METHOD(TApp, "ComplexWithDelimiter", "[newparse]") {
97 97 cx comp{1, 2};
98   - app.add_complex("-c,--complex", comp, "", true)->delimiter('+');
  98 + app.add_complex("-c,--complex", comp)->capture_default_str()->delimiter('+');
99 99  
100 100 args = {"-c", "4+3i"};
101 101  
... ... @@ -127,7 +127,7 @@ TEST_CASE_METHOD(TApp, &quot;ComplexWithDelimiter&quot;, &quot;[newparse]&quot;) {
127 127  
128 128 TEST_CASE_METHOD(TApp, "ComplexWithDelimiterOption", "[newparse]") {
129 129 cx comp{1, 2};
130   - app.add_option("-c,--complex", comp, "", true)->delimiter('+');
  130 + app.add_option("-c,--complex", comp)->capture_default_str()->delimiter('+');
131 131  
132 132 args = {"-c", "4+3i"};
133 133  
... ...
tests/OptionTypeTest.cpp
... ... @@ -240,7 +240,7 @@ TEST_CASE_METHOD(TApp, &quot;CharOption&quot;, &quot;[optiontype]&quot;) {
240 240  
241 241 TEST_CASE_METHOD(TApp, "vectorDefaults", "[optiontype]") {
242 242 std::vector<int> vals{4, 5};
243   - auto opt = app.add_option("--long", vals, "", true);
  243 + auto opt = app.add_option("--long", vals)->capture_default_str();
244 244  
245 245 args = {"--long", "[1,2,3]"};
246 246  
... ...
tests/SetTest.cpp
... ... @@ -373,7 +373,7 @@ TEST_CASE_METHOD(TApp, &quot;NumericalSets&quot;, &quot;[set]&quot;) {
373 373  
374 374 TEST_CASE_METHOD(TApp, "SetWithDefaults", "[set]") {
375 375 int someint{2};
376   - app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
  376 + app.add_option("-a", someint)->capture_default_str()->check(CLI::IsMember({1, 2, 3, 4}));
377 377  
378 378 args = {"-a1", "-a2"};
379 379  
... ... @@ -382,7 +382,7 @@ TEST_CASE_METHOD(TApp, &quot;SetWithDefaults&quot;, &quot;[set]&quot;) {
382 382  
383 383 TEST_CASE_METHOD(TApp, "SetWithDefaultsConversion", "[set]") {
384 384 int someint{2};
385   - app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
  385 + app.add_option("-a", someint)->capture_default_str()->check(CLI::IsMember({1, 2, 3, 4}));
386 386  
387 387 args = {"-a", "hi"};
388 388  
... ... @@ -391,7 +391,7 @@ TEST_CASE_METHOD(TApp, &quot;SetWithDefaultsConversion&quot;, &quot;[set]&quot;) {
391 391  
392 392 TEST_CASE_METHOD(TApp, "SetWithDefaultsIC", "[set]") {
393 393 std::string someint = "ho";
394   - app.add_option("-a", someint, "", true)->check(CLI::IsMember({"Hi", "Ho"}));
  394 + app.add_option("-a", someint)->capture_default_str()->check(CLI::IsMember({"Hi", "Ho"}));
395 395  
396 396 args = {"-aHi", "-aHo"};
397 397  
... ... @@ -415,7 +415,7 @@ TEST_CASE_METHOD(TApp, &quot;InSet&quot;, &quot;[set]&quot;) {
415 415 TEST_CASE_METHOD(TApp, "InSetWithDefault", "[set]") {
416 416  
417 417 std::string choice = "one";
418   - app.add_option("-q,--quick", choice, "", true)->check(CLI::IsMember({"one", "two", "three"}));
  418 + app.add_option("-q,--quick", choice)->capture_default_str()->check(CLI::IsMember({"one", "two", "three"}));
419 419  
420 420 run();
421 421 CHECK(choice == "one");
... ... @@ -432,7 +432,9 @@ TEST_CASE_METHOD(TApp, &quot;InSetWithDefault&quot;, &quot;[set]&quot;) {
432 432 TEST_CASE_METHOD(TApp, "InCaselessSetWithDefault", "[set]") {
433 433  
434 434 std::string choice = "one";
435   - app.add_option("-q,--quick", choice, "", true)->transform(CLI::IsMember({"one", "two", "three"}, CLI::ignore_case));
  435 + app.add_option("-q,--quick", choice)
  436 + ->capture_default_str()
  437 + ->transform(CLI::IsMember({"one", "two", "three"}, CLI::ignore_case));
436 438  
437 439 run();
438 440 CHECK(choice == "one");
... ... @@ -494,7 +496,7 @@ TEST_CASE_METHOD(TApp, &quot;FailMutableSet&quot;, &quot;[set]&quot;) {
494 496 int choice{0};
495 497 auto vals = std::shared_ptr<std::set<int>>(new std::set<int>({1, 2, 3}));
496 498 app.add_option("-q,--quick", choice)->check(CLI::IsMember(vals));
497   - app.add_option("-s,--slow", choice, "", true)->check(CLI::IsMember(vals));
  499 + app.add_option("-s,--slow", choice)->capture_default_str()->check(CLI::IsMember(vals));
498 500  
499 501 args = {"--quick=hello"};
500 502 CHECK_THROWS_AS(run(), CLI::ValidationError);
... ... @@ -651,7 +653,7 @@ TEST_CASE_METHOD(TApp, &quot;AddRemoveSetItems&quot;, &quot;[set]&quot;) {
651 653  
652 654 std::string type1, type2;
653 655 app.add_option("--type1", type1)->check(CLI::IsMember(&items));
654   - app.add_option("--type2", type2, "", true)->check(CLI::IsMember(&items));
  656 + app.add_option("--type2", type2)->capture_default_str()->check(CLI::IsMember(&items));
655 657  
656 658 args = {"--type1", "TYPE1", "--type2", "TYPE2"};
657 659  
... ... @@ -682,7 +684,7 @@ TEST_CASE_METHOD(TApp, &quot;AddRemoveSetItemsNoCase&quot;, &quot;[set]&quot;) {
682 684  
683 685 std::string type1, type2;
684 686 app.add_option("--type1", type1)->transform(CLI::IsMember(&items, CLI::ignore_case));
685   - app.add_option("--type2", type2, "", true)->transform(CLI::IsMember(&items, CLI::ignore_case));
  687 + app.add_option("--type2", type2)->capture_default_str()->transform(CLI::IsMember(&items, CLI::ignore_case));
686 688  
687 689 args = {"--type1", "TYPe1", "--type2", "TyPE2"};
688 690  
... ...
tests/SubcommandTest.cpp
... ... @@ -109,7 +109,7 @@ TEST_CASE_METHOD(TApp, &quot;CrazyNameSubcommand&quot;, &quot;[subcom]&quot;) {
109 109 TEST_CASE_METHOD(TApp, "RequiredAndSubcommands", "[subcom]") {
110 110  
111 111 std::string baz;
112   - app.add_option("baz", baz, "Baz Description", true)->required();
  112 + app.add_option("baz", baz, "Baz Description")->required()->capture_default_str();
113 113 auto foo = app.add_subcommand("foo");
114 114 auto bar = app.add_subcommand("bar");
115 115  
... ...