Skip to content

Commit 88dea3c

Browse files
mjdeckervprus
authored andcommitted
Stop options with implicit value from consuming separate tokens.
The current documentation states that if an option has implicit value, it will only consume adjacent token.
1 parent 145e572 commit 88dea3c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

include/boost/program_options/value_semantic.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ namespace boost { namespace program_options {
3939
should be present on the command line. */
4040
virtual unsigned max_tokens() const = 0;
4141

42+
/** Returns true if the option should only take adjacent token,
43+
not one from further command-line arguments.
44+
*/
45+
virtual bool adjacent_tokens_only() const = 0;
46+
4247
/** Returns true if values from different sources should be composed.
4348
Otherwise, value from the first source is used and values from
4449
other sources are discarded.
@@ -49,7 +54,7 @@ namespace boost { namespace program_options {
4954
5055
*/
5156
virtual bool is_required() const = 0;
52-
57+
5358
/** Parses a group of tokens that specify a value of option.
5459
Stores the result in 'value_store', using whatever representation
5560
is desired. May be be called several times if value of the same
@@ -135,6 +140,7 @@ namespace boost { namespace program_options {
135140

136141
unsigned min_tokens() const;
137142
unsigned max_tokens() const;
143+
bool adjacent_tokens_only() const { return false; }
138144

139145
bool is_composing() const { return false; }
140146

@@ -322,6 +328,8 @@ namespace boost { namespace program_options {
322328
}
323329
}
324330

331+
bool adjacent_tokens_only() const { return !m_implicit_value.empty(); }
332+
325333
bool is_required() const { return m_required; }
326334

327335
/** Creates an instance of the 'validator' class and calls

src/cmdline.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ namespace boost { namespace program_options { namespace detail {
313313
if (!xd)
314314
continue;
315315

316+
if (xd->semantic()->adjacent_tokens_only())
317+
continue;
318+
316319
unsigned min_tokens = xd->semantic()->min_tokens();
317320
unsigned max_tokens = xd->semantic()->max_tokens();
318321
if (min_tokens < max_tokens && opt.value.size() < max_tokens)

0 commit comments

Comments
 (0)