Skip to content

Commit 28c5d48

Browse files
OptionParser.hcpp: added an option to output a program description in raw mode, where all formatting is kept; the default is to make lines wrap at a particular width and turn multiple spaces into a single space
1 parent a622757 commit 28c5d48

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

OptionParser.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,20 @@ string OptionParser::about_message() const {
533533
static const char *PROGRAM_NAME_TAG = "PROGRAM: ";
534534
static const std::regex whitespace_re(R"([\s]+)");
535535

536-
// remove newlines
537-
string tmp_descr{prog_descr};
538-
regex_replace(begin(tmp_descr), cbegin(tmp_descr), cend(tmp_descr),
539-
whitespace_re, " ");
540-
tmp_descr.erase(tmp_descr.find_last_not_of(' ') + 1);
541-
tmp_descr.erase(0, tmp_descr.find_first_not_of(' '));
542-
543-
vector<string> parts;
544-
smithlab::split_whitespace(tmp_descr, parts);
536+
std::vector<std::string> parts = [&] {
537+
if (prog_descr_is_raw)
538+
return std::vector<std::string>(1, prog_descr);
539+
// remove newlines
540+
std::string tmp_descr{prog_descr};
541+
std::regex_replace(std::begin(tmp_descr), std::cbegin(tmp_descr),
542+
std::cend(tmp_descr), whitespace_re, " ");
543+
tmp_descr.erase(tmp_descr.find_last_not_of(' ') + 1);
544+
tmp_descr.erase(0, tmp_descr.find_first_not_of(' '));
545+
546+
vector<string> parts;
547+
smithlab::split_whitespace(tmp_descr, parts);
548+
return parts;
549+
}();
545550

546551
std::ostringstream ss;
547552
ss << PROGRAM_NAME_TAG << prog_name << endl;

OptionParser.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ class OptionParser {
128128
}
129129

130130
std::string option_missing_message() const;
131+
void set_prog_descr_raw() { prog_descr_is_raw = true; }
131132

132133
static const bool OPTIONAL = false;
133134
static const bool REQUIRED = true;
134135

135136
private:
136137
std::string prog_name;
137138
std::string prog_descr;
139+
bool prog_descr_is_raw{};
138140
std::string noflag_message;
139141
std::vector<Option> options;
140142

0 commit comments

Comments
 (0)