mirror of
https://github.com/boostorg/program_options.git
synced 2026-01-20 04:42:24 +00:00
Compare commits
24 Commits
feature/tr
...
boost-1.34
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d58b178428 | ||
|
|
87938cfa8e | ||
|
|
9a73a1c412 | ||
|
|
37143a449d | ||
|
|
2e0e9fd30b | ||
|
|
1bd588d677 | ||
|
|
d83e0dea37 | ||
|
|
54daca4c09 | ||
|
|
f4eac99310 | ||
|
|
a367a1b021 | ||
|
|
720d0455dd | ||
|
|
aad1a60172 | ||
|
|
1e4d1dee3d | ||
|
|
e718d0a8a5 | ||
|
|
ab30ec28eb | ||
|
|
682f1b7670 | ||
|
|
43577d0ca8 | ||
|
|
d05b400b13 | ||
|
|
4863727509 | ||
|
|
7d90a1b1b2 | ||
|
|
ac9830625b | ||
|
|
252a3f9ebd | ||
|
|
b1dc87da3c | ||
|
|
1fbf955272 |
@@ -1,49 +0,0 @@
|
||||
|
||||
subproject libs/program_options/build ;
|
||||
|
||||
SOURCES = cmdline config_file options_description parsers variables_map
|
||||
value_semantic positional_options utf8_codecvt_facet convert
|
||||
winmain
|
||||
;
|
||||
|
||||
lib boost_program_options
|
||||
: ../src/$(SOURCES).cpp
|
||||
: # build requirements
|
||||
[ common-names ] # magic for install and auto-link features
|
||||
<include>$(BOOST_ROOT) <sysinclude>$(BOOST_ROOT)
|
||||
std::locale-support
|
||||
: debug release # build variants
|
||||
;
|
||||
|
||||
dll boost_program_options
|
||||
: ../src/$(SOURCES).cpp
|
||||
: # build requirements
|
||||
[ common-names ] # magic for install and auto-link features
|
||||
<define>BOOST_ALL_DYN_LINK=1 # tell source we're building dll's
|
||||
<runtime-link>dynamic # build only for dynamic runtimes
|
||||
<include>$(BOOST_ROOT) <sysinclude>$(BOOST_ROOT)
|
||||
# The following really turns on static runtime linking
|
||||
# which leads to runtime crashes when using DLL, so
|
||||
# seem DLL is not usable on Metrowerks 8
|
||||
# std::facet-support std::locale-support
|
||||
: debug release # build variants
|
||||
;
|
||||
|
||||
install program_options lib
|
||||
: <lib>boost_program_options <dll>boost_program_options
|
||||
;
|
||||
|
||||
stage stage/lib : <lib>boost_program_options <dll>boost_program_options
|
||||
:
|
||||
# copy to a path rooted at BOOST_ROOT:
|
||||
<locate>$(BOOST_ROOT)
|
||||
# make sure the names of the libraries are correctly named:
|
||||
[ common-names ]
|
||||
# add this target to the "stage" and "all" psuedo-targets:
|
||||
<target>stage
|
||||
<target>all
|
||||
:
|
||||
debug release
|
||||
;
|
||||
|
||||
# end
|
||||
@@ -4,6 +4,11 @@
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="../../../doc/html/program_options.html">../../../doc/html/program_options.html</a>
|
||||
<a href="../../../doc/html/program_options.html">../../../doc/html/program_options.html</a>
|
||||
<hr>
|
||||
<p>© Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -348,7 +348,7 @@ positional_options_description pd; pd.add("input-file", 1);
|
||||
given the same name.
|
||||
<programlisting>
|
||||
positional_options_description pd;
|
||||
pd.add("output-file", 2).add_optional("input-file", -1);
|
||||
pd.add("output-file", 2).add("input-file", -1);
|
||||
</programlisting>
|
||||
In the above example, the first two positional options will be associated
|
||||
with name "output-file", and any others with the name "input-file".
|
||||
|
||||
@@ -96,7 +96,7 @@ Compression level was set to 10.
|
||||
<para>An option value, surely, can have other types than <code>int</code>, and
|
||||
can have other interesting properties, which we'll discuss right now. The
|
||||
complete version of the code snipped below can be found in
|
||||
"example/options_description.cpp".</para>
|
||||
<filename>example/options_description.cpp</filename>.</para>
|
||||
|
||||
<para>Imagine we're writing a compiler. It should take the optimization
|
||||
level, a number of include paths, and a number of input files, and perform some
|
||||
@@ -115,21 +115,29 @@ desc.add_options()
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>The "--help" option should be familiar from the previous example.
|
||||
It's a good idea to have this option in all cases.</para>
|
||||
<para>The <literal>"help"</literal> option should be familiar from
|
||||
the previous example. It's a good idea to have this option in all cases.
|
||||
</para>
|
||||
|
||||
<para>The "optimization" option shows two new features. First, we specify
|
||||
<para>The <literal>"optimization"</literal> option shows two new features. First, we specify
|
||||
the address of the variable(<code>&opt</code>). After storing values, that
|
||||
variable will have the value of the option. Second, we specify a default
|
||||
value of 10, which will be used if no value is specified by the user.
|
||||
</para>
|
||||
|
||||
<para>The "include-path" option is an example of the only case where
|
||||
the interface of the <code>options_description</code> class serves only one
|
||||
<para>The <literal>"include-path"</literal> option is an example of the
|
||||
only case where the interface of the <code>options_description</code>
|
||||
class serves only one
|
||||
source -- the command line. Users typically like to use short option names
|
||||
for common options, and the "include-path,I" name specifies that short
|
||||
option name is "I". So, both "--include-path" and "-I" can be used.
|
||||
</para>
|
||||
|
||||
<para>Note also that the type of the <literal>"include-path"</literal>
|
||||
option is <type>std::vector</type>. The library provides special
|
||||
support for vectors -- it will be possible to specify the option several
|
||||
times, and all specified values will be collected in one vector.
|
||||
</para>
|
||||
|
||||
<para>The "input-file" option specifies the list of files to
|
||||
process. That's okay for a start, but, of course, writing something like:
|
||||
@@ -337,7 +345,7 @@ Optimization level is 4
|
||||
|
||||
<!--
|
||||
Local Variables:
|
||||
mode: xml
|
||||
mode: nxml
|
||||
sgml-indent-data: t
|
||||
sgml-parent-document: ("program_options.xml" "section")
|
||||
sgml-set-face: t
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
|
||||
subproject libs/program_options/example ;
|
||||
|
||||
rule program-options-example ( name extra-sources * )
|
||||
{
|
||||
exe $(name) : $(name).cpp <lib>../build/boost_program_options $(extra-sources)
|
||||
: <include>$(BOOST_ROOT) ;
|
||||
}
|
||||
|
||||
program-options-example first ;
|
||||
program-options-example options_description ;
|
||||
program-options-example multiple_sources ;
|
||||
program-options-example custom_syntax ;
|
||||
program-options-example response_file ;
|
||||
program-options-example option_groups ;
|
||||
program-options-example real ;
|
||||
program-options-example regex <lib>../../regex/build/boost_regex ;
|
||||
|
||||
|
||||
#program-options-example prefix ;
|
||||
|
||||
|
||||
|
||||
@@ -12,13 +12,13 @@ namespace boost { namespace program_options { namespace command_line_style {
|
||||
There are "long" options, which start with "--" and "short",
|
||||
which start with either "-" or "/". Both kinds can be allowed or
|
||||
disallowed, see allow_long and allow_short. The allowed character
|
||||
for short option is also configurable.
|
||||
for short options is also configurable.
|
||||
|
||||
Option's value can be specified in the same token as value
|
||||
Option's value can be specified in the same token as name
|
||||
("--foo=bar"), or in the next token.
|
||||
|
||||
It's possible to introduce long option by the same character as
|
||||
long option, see allow_long_disguise.
|
||||
It's possible to introduce long options by the same character as
|
||||
short options, see allow_long_disguise.
|
||||
|
||||
Finally, guessing (specifying only prefix of option) and case
|
||||
insensitive processing are supported.
|
||||
@@ -39,7 +39,7 @@ namespace boost { namespace program_options { namespace command_line_style {
|
||||
@endverbatim
|
||||
*/
|
||||
long_allow_adjacent = allow_slash_for_short << 1,
|
||||
/** Allow option parameter in the same token for
|
||||
/** Allow option parameter in the next token for
|
||||
long options. */
|
||||
long_allow_next = long_allow_adjacent << 1,
|
||||
/** Allow option parameter in the same token for
|
||||
@@ -59,7 +59,7 @@ namespace boost { namespace program_options { namespace command_line_style {
|
||||
/** Allow abbreviated spellings for long options,
|
||||
if they unambiguously identify long option.
|
||||
No long option name should be prefix of other
|
||||
long option name is guessing is in effect.
|
||||
long option name if guessing is in effect.
|
||||
*/
|
||||
allow_guessing = allow_sticky << 1,
|
||||
/** Ignore the difference in case for options.
|
||||
|
||||
@@ -82,11 +82,12 @@ namespace boost { namespace program_options {
|
||||
validation_error(const std::string& what) : error(what) {}
|
||||
~validation_error() throw() {}
|
||||
void set_option_name(const std::string& option);
|
||||
|
||||
const char* what() const throw();
|
||||
private:
|
||||
mutable std::string m_message; // For on-demand formatting in 'what'
|
||||
std::string m_option_name; // The name of the option which
|
||||
// caused the exception.
|
||||
const char* what() const throw();
|
||||
};
|
||||
|
||||
class BOOST_PROGRAM_OPTIONS_DECL invalid_option_value
|
||||
|
||||
@@ -37,10 +37,11 @@ namespace boost { namespace program_options {
|
||||
No calls to 'add' can be made after call with 'max_value' equal to
|
||||
'-1'.
|
||||
*/
|
||||
void add(const char* name, int max_count);
|
||||
positional_options_description&
|
||||
add(const char* name, int max_count);
|
||||
|
||||
/** Returns the maximum number of positional options that can
|
||||
be present. Can return numeric_limits<unsigned>::max() to
|
||||
be present. Can return (numeric_limits<unsigned>::max)() to
|
||||
indicate unlimited number. */
|
||||
unsigned max_total_count() const;
|
||||
|
||||
|
||||
@@ -24,6 +24,27 @@ namespace boost { namespace program_options {
|
||||
class value_semantic;
|
||||
class variables_map;
|
||||
|
||||
// forward declaration
|
||||
|
||||
/** Stores in 'm' all options that are defined in 'options'.
|
||||
If 'm' already has a non-defaulted value of an option, that value
|
||||
is not changed, even if 'options' specify some value.
|
||||
*/
|
||||
BOOST_PROGRAM_OPTIONS_DECL void store(const basic_parsed_options<char>& options, variables_map& m,
|
||||
bool utf8 = false);
|
||||
|
||||
/** Stores in 'm' all options that are defined in 'options'.
|
||||
If 'm' already has a non-defaulted value of an option, that value
|
||||
is not changed, even if 'options' specify some value.
|
||||
This is wide character variant.
|
||||
*/
|
||||
BOOST_PROGRAM_OPTIONS_DECL void store(const basic_parsed_options<wchar_t>& options,
|
||||
variables_map& m);
|
||||
|
||||
|
||||
/** Runs all 'notify' function for options in 'm'. */
|
||||
BOOST_PROGRAM_OPTIONS_DECL void notify(variables_map& m);
|
||||
|
||||
/** Class holding value of option. Contains details about how the
|
||||
value is set and allows to conveniently obtain the value.
|
||||
*/
|
||||
@@ -36,10 +57,15 @@ namespace boost { namespace program_options {
|
||||
|
||||
/** If stored value if of type T, returns that value. Otherwise,
|
||||
throws boost::bad_any_cast exception. */
|
||||
template<class T> const T& as() const;
|
||||
|
||||
/** @overload */
|
||||
template<class T> T& as();
|
||||
template<class T>
|
||||
const T& as() const {
|
||||
return boost::any_cast<const T&>(v);
|
||||
}
|
||||
/** @overload */
|
||||
template<class T>
|
||||
T& as() {
|
||||
return boost::any_cast<T&>(v);
|
||||
}
|
||||
|
||||
/// Returns true if no value is stored.
|
||||
bool empty() const;
|
||||
@@ -61,10 +87,9 @@ namespace boost { namespace program_options {
|
||||
// be easily accessible, so we need to store semantic here.
|
||||
shared_ptr<const value_semantic> m_value_semantic;
|
||||
|
||||
friend void BOOST_PROGRAM_OPTIONS_DECL
|
||||
store(const basic_parsed_options<char>& options,
|
||||
friend void store(const basic_parsed_options<char>& options,
|
||||
variables_map& m, bool);
|
||||
friend void BOOST_PROGRAM_OPTIONS_DECL notify(variables_map& m);
|
||||
friend void notify(variables_map& m);
|
||||
};
|
||||
|
||||
/** Implements string->string mapping with convenient value casting
|
||||
@@ -104,7 +129,11 @@ namespace boost { namespace program_options {
|
||||
const abstract_variables_map* m_next;
|
||||
};
|
||||
|
||||
/** Concrete variables map which store variables in real map. */
|
||||
/** Concrete variables map which store variables in real map.
|
||||
|
||||
This class is derived from std::map<std::string, variable_value>,
|
||||
so you can use all map operators to examine its content.
|
||||
*/
|
||||
class BOOST_PROGRAM_OPTIONS_DECL variables_map : public abstract_variables_map,
|
||||
public std::map<std::string, variable_value>
|
||||
{
|
||||
@@ -130,25 +159,6 @@ namespace boost { namespace program_options {
|
||||
bool utf8);
|
||||
};
|
||||
|
||||
/** Stores in 'm' all options that are defined in 'options'.
|
||||
If 'm' already has a non-defaulted value of an option, that value
|
||||
is not changed, even if 'options' specify some value.
|
||||
*/
|
||||
BOOST_PROGRAM_OPTIONS_DECL void store(const basic_parsed_options<char>& options, variables_map& m,
|
||||
bool utf8 = false);
|
||||
|
||||
/** Stores in 'm' all options that are defined in 'options'.
|
||||
If 'm' already has a non-defaulted value of an option, that value
|
||||
is not changed, even if 'options' specify some value.
|
||||
This is wide character variant.
|
||||
*/
|
||||
BOOST_PROGRAM_OPTIONS_DECL void store(const basic_parsed_options<wchar_t>& options,
|
||||
variables_map& m);
|
||||
|
||||
|
||||
/** Runs all 'notify' function for options in 'm'. */
|
||||
BOOST_PROGRAM_OPTIONS_DECL void notify(variables_map& m);
|
||||
|
||||
|
||||
/*
|
||||
* Templates/inlines
|
||||
@@ -180,18 +190,6 @@ namespace boost { namespace program_options {
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
const T&
|
||||
variable_value::as() const {
|
||||
return boost::any_cast<const T&>(v);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T&
|
||||
variable_value::as() {
|
||||
return boost::any_cast<T&>(v);
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="../../doc/html/program_options.html">../../doc/html/program_options.html</a>
|
||||
<a href="../../doc/html/program_options.html">../../doc/html/program_options.html</a>
|
||||
<hr>
|
||||
<p>© Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
@@ -498,7 +498,8 @@ namespace boost { namespace program_options { namespace detail {
|
||||
if (!r.first.empty()) {
|
||||
option next;
|
||||
next.string_key = r.first;
|
||||
next.value.push_back(r.second);
|
||||
if (!r.second.empty())
|
||||
next.value.push_back(r.second);
|
||||
result.push_back(next);
|
||||
args.erase(args.begin());
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
using namespace std;
|
||||
|
||||
namespace boost { namespace program_options {
|
||||
@@ -390,13 +391,12 @@ namespace boost { namespace program_options {
|
||||
}
|
||||
}
|
||||
|
||||
string::const_iterator line_end;
|
||||
|
||||
line_end = line_begin + line_length;
|
||||
if (line_end > par_end)
|
||||
{
|
||||
line_end = par_end;
|
||||
}
|
||||
// Take care to never increment the iterator past
|
||||
// the end, since MSVC 8.0 (brokenly), assumes that
|
||||
// doing that, even if no access happens, is a bug.
|
||||
unsigned remaining = distance(line_begin, par_end);
|
||||
string::const_iterator line_end = line_begin +
|
||||
((remaining < line_length) ? remaining : line_length);
|
||||
|
||||
// prevent chopped words
|
||||
// Is line_end between two non-space characters?
|
||||
@@ -412,9 +412,9 @@ namespace boost { namespace program_options {
|
||||
|
||||
if (last_space != line_begin)
|
||||
{
|
||||
// is last_space within the second half ot the
|
||||
// is last_space within the second half of the
|
||||
// current line
|
||||
if (unsigned(distance(last_space, line_end)) <
|
||||
if ((unsigned)std::distance(last_space, line_end) <
|
||||
(line_length - indent) / 2)
|
||||
{
|
||||
line_end = last_space;
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace boost { namespace program_options {
|
||||
positional_options_description::positional_options_description()
|
||||
{}
|
||||
|
||||
void
|
||||
positional_options_description&
|
||||
positional_options_description::add(const char* name, int max_count)
|
||||
{
|
||||
assert(max_count != -1 || m_trailing.empty());
|
||||
@@ -27,7 +27,7 @@ namespace boost { namespace program_options {
|
||||
else {
|
||||
m_names.resize(m_names.size() + max_count, name);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
unsigned
|
||||
|
||||
@@ -170,9 +170,12 @@ namespace boost { namespace program_options {
|
||||
{
|
||||
check_first_occurrence(v);
|
||||
string s(get_single_string(xs));
|
||||
if (*s.begin() == '\'' && *s.rbegin() == '\'' ||
|
||||
*s.begin() == '"' && *s.rbegin() == '"')
|
||||
if (!s.empty() && (
|
||||
(*s.begin() == '\'' && *s.rbegin() == '\'' ||
|
||||
*s.begin() == '"' && *s.rbegin() == '"')))
|
||||
{
|
||||
v = any(s.substr(1, s.size()-2));
|
||||
}
|
||||
else
|
||||
v = any(s);
|
||||
}
|
||||
|
||||
@@ -35,8 +35,11 @@ namespace boost { namespace program_options {
|
||||
|
||||
std::set<std::string> new_final;
|
||||
|
||||
// Declared once, to please Intel in VC++ mode;
|
||||
unsigned i;
|
||||
|
||||
// First, convert/store all given options
|
||||
for (size_t i = 0; i < options.options.size(); ++i) {
|
||||
for (i = 0; i < options.options.size(); ++i) {
|
||||
|
||||
const string& name = options.options[i].string_key;
|
||||
// Skip positional options without name
|
||||
@@ -92,7 +95,7 @@ namespace boost { namespace program_options {
|
||||
|
||||
// Second, apply default values.
|
||||
const vector<shared_ptr<option_description> >& all = desc.options();
|
||||
for(unsigned i = 0; i < all.size(); ++i)
|
||||
for(i = 0; i < all.size(); ++i)
|
||||
{
|
||||
const option_description& d = *all[i];
|
||||
string key = d.key("");
|
||||
|
||||
47
test/Jamfile
47
test/Jamfile
@@ -1,47 +0,0 @@
|
||||
|
||||
subproject libs/program_options/test ;
|
||||
|
||||
import testing ;
|
||||
|
||||
rule program-options-test ( name )
|
||||
{
|
||||
return [
|
||||
run $(name).cpp <lib>../build/boost_program_options
|
||||
<lib>../../test/build/boost_test_exec_monitor : :
|
||||
: <include>$(BOOST_ROOT)
|
||||
std::locale-support ]
|
||||
;
|
||||
}
|
||||
|
||||
rule program-options-dll-test ( name )
|
||||
{
|
||||
return [
|
||||
run $(name).cpp <dll>../build/boost_program_options
|
||||
<lib>../../test/build/boost_test_exec_monitor : :
|
||||
: <include>$(BOOST_ROOT)
|
||||
<define>BOOST_ALL_DYN_LINK=1
|
||||
<runtime-link>dynamic
|
||||
: $(name)_dll ]
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
test-suite program_options :
|
||||
[ program-options-test options_description_test ]
|
||||
[ program-options-test parsers_test ]
|
||||
[ program-options-test variable_map_test ]
|
||||
[ program-options-test cmdline_test ]
|
||||
[ program-options-test positional_options_test ]
|
||||
[ program-options-test unicode_test ]
|
||||
[ program-options-test winmain ]
|
||||
[ program-options-dll-test options_description_test ]
|
||||
[ program-options-dll-test parsers_test ]
|
||||
[ program-options-dll-test variable_map_test ]
|
||||
[ program-options-dll-test cmdline_test ]
|
||||
[ program-options-dll-test positional_options_test ]
|
||||
[ program-options-dll-test unicode_test ]
|
||||
[ program-options-dll-test winmain ]
|
||||
|
||||
|
||||
;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
project
|
||||
: requirements
|
||||
<library>../build//boost_program_options
|
||||
<library>/boost/test//boost_test_exec_monitor
|
||||
<library>/boost/test//boost_test_exec_monitor/<link>static
|
||||
<link>static
|
||||
|
||||
# <define>_GLIBCXX_CONCEPT_CHECKS
|
||||
@@ -13,7 +13,7 @@ rule po-test ( source )
|
||||
{
|
||||
return
|
||||
[ run $(source) ]
|
||||
[ run $(source) : : : <link>shared <define>BOOST_ALL_DYN_LINK=1
|
||||
[ run $(source) : : : <link>shared <define>BOOST_PROGRAM_OPTIONS_DYN_LINK=1
|
||||
: $(source:B)_dll ]
|
||||
;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ using namespace boost;
|
||||
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
void test_type()
|
||||
@@ -61,9 +62,25 @@ void test_approximation()
|
||||
// BOOST_CHECK(*(++a.begin()) == "foo");
|
||||
}
|
||||
|
||||
void test_formatting()
|
||||
{
|
||||
// Long option descriptions used to crash on MSVC-8.0.
|
||||
options_description desc;
|
||||
desc.add_options()(
|
||||
"test", new untyped_value(),
|
||||
"foo foo foo foo foo foo foo foo foo foo foo foo foo foo"
|
||||
"foo foo foo foo foo foo foo foo foo foo foo foo foo foo"
|
||||
"foo foo foo foo foo foo foo foo foo foo foo foo foo foo"
|
||||
"foo foo foo foo foo foo foo foo foo foo foo foo foo foo");
|
||||
|
||||
stringstream ss;
|
||||
ss << desc;
|
||||
}
|
||||
|
||||
int test_main(int, char* [])
|
||||
{
|
||||
test_type();
|
||||
test_approximation();
|
||||
test_formatting();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -133,6 +133,16 @@ void test_command_line()
|
||||
check_value(a4[0], "foo", "4");
|
||||
check_value(a4[1], "bar", "11");
|
||||
|
||||
// Check that we don't crash on empty values of type 'string'
|
||||
char* cmdline4[] = {"", "--open", ""};
|
||||
options_description desc2;
|
||||
desc2.add_options()
|
||||
("open", po::value<string>())
|
||||
;
|
||||
variables_map vm;
|
||||
po::store(po::parse_command_line(3, cmdline4, desc2), vm);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -49,28 +49,31 @@ void test_parsing()
|
||||
("first", po::value<int>())
|
||||
("second", po::value<int>())
|
||||
("input-file", po::value< vector<string> >())
|
||||
("some-other", po::value<string>())
|
||||
;
|
||||
|
||||
positional_options_description p;
|
||||
p.add("input-file", 2);
|
||||
p.add("input-file", 2).add("some-other", 1);
|
||||
|
||||
vector<string> args;
|
||||
args.push_back("--first=10");
|
||||
args.push_back("file1");
|
||||
args.push_back("--second=10");
|
||||
args.push_back("file2");
|
||||
args.push_back("file3");
|
||||
|
||||
// Check that positional options are handled.
|
||||
parsed_options parsed =
|
||||
command_line_parser(args).options(desc).positional(p).run();
|
||||
|
||||
BOOST_REQUIRE(parsed.options.size() == 4);
|
||||
BOOST_REQUIRE(parsed.options.size() == 5);
|
||||
BOOST_CHECK_EQUAL(parsed.options[1].string_key, "input-file");
|
||||
BOOST_CHECK_EQUAL(parsed.options[1].value[0], "file1");
|
||||
BOOST_CHECK_EQUAL(parsed.options[3].string_key, "input-file");
|
||||
BOOST_CHECK_EQUAL(parsed.options[3].value[0], "file2");
|
||||
BOOST_CHECK_EQUAL(parsed.options[4].value[0], "file3");
|
||||
|
||||
args.push_back("file3");
|
||||
args.push_back("file4");
|
||||
|
||||
// Check that excessive number of positional options is detected.
|
||||
BOOST_CHECK_THROW(command_line_parser(args).options(desc).positional(p)
|
||||
|
||||
Reference in New Issue
Block a user