summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-03-24 13:00:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-03-24 13:00:05 +0200
commit74fff9901d9529cdde4ed42254aa21afe466ac3a (patch)
treeb95c93bc49e0ff9d9a1d7b26931f473f5e68aff9 /cli
parenta2884d0ae08c4c13998570aa0073b05dec82c543 (diff)
Add --keep-separator option
Diffstat (limited to 'cli')
-rw-r--r--cli/options.cli6
-rw-r--r--cli/options.cxx10
-rw-r--r--cli/options.hxx10
-rw-r--r--cli/options.ixx20
-rw-r--r--cli/source.cxx13
5 files changed, 55 insertions, 4 deletions
diff --git a/cli/options.cli b/cli/options.cli
index 30b45b3..97b63aa 100644
--- a/cli/options.cli
+++ b/cli/options.cli
@@ -575,6 +575,12 @@ class options
option separator to the empty value if you don't want this functionality."
};
+ bool --keep-separator
+ {
+ "Leave the option separator in the scanner. This is primarily useful for
+ incremental option parsing."
+ };
+
bool --include-with-brackets
{
"Use angle brackets (\cb{<>}) instead of quotes (\cb{\"\"}) in the
diff --git a/cli/options.cxx b/cli/options.cxx
index 68b964b..0a9c0e4 100644
--- a/cli/options.cxx
+++ b/cli/options.cxx
@@ -680,6 +680,7 @@ options ()
option_prefix_specified_ (false),
option_separator_ ("--"),
option_separator_specified_ (false),
+ keep_separator_ (),
include_with_brackets_ (),
include_prefix_ (),
include_prefix_specified_ (false),
@@ -815,6 +816,7 @@ options (int& argc,
option_prefix_specified_ (false),
option_separator_ ("--"),
option_separator_specified_ (false),
+ keep_separator_ (),
include_with_brackets_ (),
include_prefix_ (),
include_prefix_specified_ (false),
@@ -953,6 +955,7 @@ options (int start,
option_prefix_specified_ (false),
option_separator_ ("--"),
option_separator_specified_ (false),
+ keep_separator_ (),
include_with_brackets_ (),
include_prefix_ (),
include_prefix_specified_ (false),
@@ -1091,6 +1094,7 @@ options (int& argc,
option_prefix_specified_ (false),
option_separator_ ("--"),
option_separator_specified_ (false),
+ keep_separator_ (),
include_with_brackets_ (),
include_prefix_ (),
include_prefix_specified_ (false),
@@ -1231,6 +1235,7 @@ options (int start,
option_prefix_specified_ (false),
option_separator_ ("--"),
option_separator_specified_ (false),
+ keep_separator_ (),
include_with_brackets_ (),
include_prefix_ (),
include_prefix_specified_ (false),
@@ -1367,6 +1372,7 @@ options (::cli::scanner& s,
option_prefix_specified_ (false),
option_separator_ ("--"),
option_separator_specified_ (false),
+ keep_separator_ (),
include_with_brackets_ (),
include_prefix_ (),
include_prefix_specified_ (false),
@@ -1594,6 +1600,8 @@ print_usage (::std::ostream& os, ::cli::usage_para p)
os << "--option-separator <sep> Use <sep> instead of the default '--' as an" << ::std::endl
<< " optional separator between options and arguments." << ::std::endl;
+ os << "--keep-separator Leave the option separator in the scanner." << ::std::endl;
+
os << "--include-with-brackets Use angle brackets (<>) instead of quotes (\"\") in" << ::std::endl
<< " the generated #include directives." << ::std::endl;
@@ -1823,6 +1831,8 @@ struct _cli_options_map_init
_cli_options_map_["--option-separator"] =
&::cli::thunk< options, std::string, &options::option_separator_,
&options::option_separator_specified_ >;
+ _cli_options_map_["--keep-separator"] =
+ &::cli::thunk< options, bool, &options::keep_separator_ >;
_cli_options_map_["--include-with-brackets"] =
&::cli::thunk< options, bool, &options::include_with_brackets_ >;
_cli_options_map_["--include-prefix"] =
diff --git a/cli/options.hxx b/cli/options.hxx
index a2998d8..a4242bc 100644
--- a/cli/options.hxx
+++ b/cli/options.hxx
@@ -1320,6 +1320,15 @@ class options
option_separator_specified (bool);
const bool&
+ keep_separator () const;
+
+ bool&
+ keep_separator ();
+
+ void
+ keep_separator (const bool&);
+
+ const bool&
include_with_brackets () const;
bool&
@@ -1524,6 +1533,7 @@ class options
bool option_prefix_specified_;
std::string option_separator_;
bool option_separator_specified_;
+ bool keep_separator_;
bool include_with_brackets_;
std::string include_prefix_;
bool include_prefix_specified_;
diff --git a/cli/options.ixx b/cli/options.ixx
index d93957e..634e7b7 100644
--- a/cli/options.ixx
+++ b/cli/options.ixx
@@ -9,6 +9,8 @@
//
// End prologue.
+#include <cassert>
+
namespace cli
{
// usage_para
@@ -2046,6 +2048,24 @@ option_separator_specified(bool x)
}
inline const bool& options::
+keep_separator () const
+{
+ return this->keep_separator_;
+}
+
+inline bool& options::
+keep_separator ()
+{
+ return this->keep_separator_;
+}
+
+inline void options::
+keep_separator(const bool& x)
+{
+ this->keep_separator_ = x;
+}
+
+inline const bool& options::
include_with_brackets () const
{
return this->include_with_brackets_;
diff --git a/cli/source.cxx b/cli/source.cxx
index 180cea8..9c88014 100644
--- a/cli/source.cxx
+++ b/cli/source.cxx
@@ -938,13 +938,18 @@ namespace
<< "const char* o = s.peek ();";
if (sep)
+ {
os << endl
<< "if (std::strcmp (o, \"" << opt_sep << "\") == 0)"
<< "{"
- << "s.skip ();" // We don't want to remove the separator.
- << "opt = false;"
- << "continue;"
- << "}";
+ << "opt = false;";
+ if (!options.keep_separator ())
+ {
+ os << "s.skip ();" // We don't want to erase the separator.
+ << "continue;";
+ }
+ os << "}";
+ }
os << "if (" << (sep ? "opt && " : "") << "_parse (o, s));";