summaryrefslogtreecommitdiff
path: root/src/support/command-line.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/support/command-line.cpp')
-rw-r--r--src/support/command-line.cpp35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/support/command-line.cpp b/src/support/command-line.cpp
index 6882dda7b..f3b9ffe25 100644
--- a/src/support/command-line.cpp
+++ b/src/support/command-line.cpp
@@ -37,7 +37,8 @@ void printWrap(std::ostream& os, int leftPad, const std::string& content) {
}
os << nextWord;
space -= nextWord.size() + 1;
- if (space > 0) os << ' ';
+ if (space > 0)
+ os << ' ';
nextWord.clear();
if (content[i] == '\n') {
os << '\n';
@@ -48,18 +49,22 @@ void printWrap(std::ostream& os, int leftPad, const std::string& content) {
}
Options::Options(const std::string& command, const std::string& description)
- : debug(false), positional(Arguments::Zero) {
- add("--help", "-h", "Show this help message and exit", Arguments::Zero,
+ : debug(false), positional(Arguments::Zero) {
+ add("--help",
+ "-h",
+ "Show this help message and exit",
+ Arguments::Zero,
[this, command, description](Options* o, const std::string&) {
std::cout << command;
- if (positional != Arguments::Zero) std::cout << ' ' << positionalName;
+ if (positional != Arguments::Zero)
+ std::cout << ' ' << positionalName;
std::cout << "\n\n";
printWrap(std::cout, 0, description);
std::cout << "\n\nOptions:\n";
size_t optionWidth = 0;
for (const auto& o : options) {
optionWidth =
- std::max(optionWidth, o.longName.size() + o.shortName.size());
+ std::max(optionWidth, o.longName.size() + o.shortName.size());
}
for (const auto& o : options) {
bool long_n_short = o.longName.size() != 0 && o.shortName.size() != 0;
@@ -72,20 +77,26 @@ Options::Options(const std::string& command, const std::string& description)
std::cout << '\n';
exit(EXIT_SUCCESS);
});
- add("--debug", "-d", "Print debug information to stderr", Arguments::Zero,
+ add("--debug",
+ "-d",
+ "Print debug information to stderr",
+ Arguments::Zero,
[&](Options* o, const std::string& arguments) { debug = true; });
}
Options::~Options() {}
-Options& Options::add(const std::string& longName, const std::string& shortName,
- const std::string& description, Arguments arguments,
+Options& Options::add(const std::string& longName,
+ const std::string& shortName,
+ const std::string& description,
+ Arguments arguments,
const Action& action) {
options.push_back({longName, shortName, description, arguments, action, 0});
return *this;
}
-Options& Options::add_positional(const std::string& name, Arguments arguments,
+Options& Options::add_positional(const std::string& name,
+ Arguments arguments,
const Action& action) {
positional = arguments;
positionalName = name;
@@ -98,7 +109,8 @@ void Options::parse(int argc, const char* argv[]) {
size_t positionalsSeen = 0;
auto dashes = [](const std::string& s) {
for (size_t i = 0;; ++i) {
- if (s[i] != '-') return i;
+ if (s[i] != '-')
+ return i;
}
};
for (size_t i = 1, e = argc; i != e; ++i) {
@@ -169,7 +181,8 @@ void Options::parse(int argc, const char* argv[]) {
break;
case Arguments::Optional:
if (!argument.size()) {
- if (i + 1 != e) argument = argv[++i];
+ if (i + 1 != e)
+ argument = argv[++i];
}
break;
}