Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarOptionParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/StarOptionParser.cpp')
-rw-r--r--source/core/StarOptionParser.cpp48
1 files changed, 24 insertions, 24 deletions
diff --git a/source/core/StarOptionParser.cpp b/source/core/StarOptionParser.cpp
index ecf6e28..f849f43 100644
--- a/source/core/StarOptionParser.cpp
+++ b/source/core/StarOptionParser.cpp
@@ -17,12 +17,12 @@ void OptionParser::setAdditionalHelp(String help) {
void OptionParser::addSwitch(String const& flag, String description) {
if (!m_options.insert(flag, Switch{flag, move(description)}).second)
- throw OptionParserException::format("Duplicate switch '-%s' added", flag);
+ throw OptionParserException::format("Duplicate switch '-{}' added", flag);
}
void OptionParser::addParameter(String const& flag, String argument, RequirementMode requirementMode, String description) {
if (!m_options.insert(flag, Parameter{flag, move(argument), requirementMode, move(description)}).second)
- throw OptionParserException::format("Duplicate flag '-%s' added", flag);
+ throw OptionParserException::format("Duplicate flag '-{}' added", flag);
}
void OptionParser::addArgument(String argument, RequirementMode requirementMode, String description) {
@@ -46,7 +46,7 @@ pair<OptionParser::Options, StringList> OptionParser::parseOptions(StringList co
String flag = arg.substr(1);
auto option = m_options.maybe(flag);
if (!option) {
- errors.append(strf("No such option '-%s'", flag));
+ errors.append(strf("No such option '-{}'", flag));
continue;
}
@@ -55,12 +55,12 @@ pair<OptionParser::Options, StringList> OptionParser::parseOptions(StringList co
} else {
auto const& parameter = option->get<Parameter>();
if (!it.hasNext()) {
- errors.append(strf("Option '-%s' must be followed by an argument", flag));
+ errors.append(strf("Option '-{}' must be followed by an argument", flag));
continue;
}
String val = it.next();
if (parameter.requirementMode != Multiple && result.parameters.contains(flag)) {
- errors.append(strf("Option with argument '-%s' specified multiple times", flag));
+ errors.append(strf("Option with argument '-{}' specified multiple times", flag));
continue;
}
result.parameters[move(flag)].append(move(val));
@@ -75,7 +75,7 @@ pair<OptionParser::Options, StringList> OptionParser::parseOptions(StringList co
if (pair.second.is<Parameter>()) {
auto const& na = pair.second.get<Parameter>();
if (na.requirementMode == Required && !result.parameters.contains(pair.first))
- errors.append(strf("Missing required flag with argument '-%s'", pair.first));
+ errors.append(strf("Missing required flag with argument '-{}'", pair.first));
}
}
@@ -91,72 +91,72 @@ pair<OptionParser::Options, StringList> OptionParser::parseOptions(StringList co
}
if (result.arguments.size() < minimumArguments)
errors.append(strf(
- "Too few positional arguments given, expected at least %s got %s", minimumArguments, result.arguments.size()));
+ "Too few positional arguments given, expected at least {} got {}", minimumArguments, result.arguments.size()));
if (result.arguments.size() > maximumArguments)
errors.append(strf(
- "Too many positional arguments given, expected at most %s got %s", maximumArguments, result.arguments.size()));
+ "Too many positional arguments given, expected at most {} got {}", maximumArguments, result.arguments.size()));
return {move(result), move(errors)};
}
void OptionParser::printHelp(std::ostream& os) const {
if (!m_commandName.empty() && !m_summary.empty())
- format(os, "%s: %s\n\n", m_commandName, m_summary);
+ format(os, "{}: {}\n\n", m_commandName, m_summary);
else if (!m_commandName.empty())
- format(os, "%s:\n\n", m_commandName);
+ format(os, "{}:\n\n", m_commandName);
else if (!m_summary.empty())
- format(os, "%s\n\n", m_summary);
+ format(os, "{}\n\n", m_summary);
String cmdLineText;
for (auto const& p : m_options) {
if (p.second.is<Switch>()) {
- cmdLineText += strf(" [-%s]", p.first);
+ cmdLineText += strf(" [-{}]", p.first);
} else {
auto const& parameter = p.second.get<Parameter>();
if (parameter.requirementMode == Optional)
- cmdLineText += strf(" [-%s <%s>]", parameter.flag, parameter.argument);
+ cmdLineText += strf(" [-{} <{}>]", parameter.flag, parameter.argument);
else if (parameter.requirementMode == Required)
- cmdLineText += strf(" -%s <%s>", parameter.flag, parameter.argument);
+ cmdLineText += strf(" -{} <{}>", parameter.flag, parameter.argument);
else if (parameter.requirementMode == Multiple)
- cmdLineText += strf(" [-%s <%s>]...", parameter.flag, parameter.argument);
+ cmdLineText += strf(" [-{} <{}>]...", parameter.flag, parameter.argument);
}
}
for (auto const& p : m_arguments) {
if (p.requirementMode == Optional)
- cmdLineText += strf(" [<%s>]", p.argumentName);
+ cmdLineText += strf(" [<{}>]", p.argumentName);
else if (p.requirementMode == Required)
- cmdLineText += strf(" <%s>", p.argumentName);
+ cmdLineText += strf(" <{}>", p.argumentName);
else
- cmdLineText += strf(" [<%s>...]", p.argumentName);
+ cmdLineText += strf(" [<{}>...]", p.argumentName);
}
if (m_commandName.empty())
- format(os, "Command Line Usage:%s\n", cmdLineText);
+ format(os, "Command Line Usage:{}\n", cmdLineText);
else
- format(os, "Command Line Usage: %s%s\n", m_commandName, cmdLineText);
+ format(os, "Command Line Usage: {}{}\n", m_commandName, cmdLineText);
for (auto const& p : m_options) {
if (p.second.is<Switch>()) {
auto const& sw = p.second.get<Switch>();
if (!sw.description.empty())
- format(os, " -%s\t- %s\n", sw.flag, sw.description);
+ format(os, " -{}\t- {}\n", sw.flag, sw.description);
}
if (p.second.is<Parameter>()) {
auto const& parameter = p.second.get<Parameter>();
if (!parameter.description.empty())
- format(os, " -%s <%s>\t- %s\n", parameter.flag, parameter.argument, parameter.description);
+ format(os, " -{} <{}>\t- {}\n", parameter.flag, parameter.argument, parameter.description);
}
}
for (auto const& p : m_arguments) {
if (!p.description.empty())
- format(os, " <%s>\t- %s\n", p.argumentName, p.description);
+ format(os, " <{}>\t- {}\n", p.argumentName, p.description);
}
if (!m_additionalHelp.empty())
- format(os, "\n%s\n", m_additionalHelp);
+ format(os, "\n{}\n", m_additionalHelp);
}
}