mirror of
https://github.com/sametersoylu/argument-parser.git
synced 2026-07-14 09:38:11 +00:00
feat: improve help text for better readability, less duplication on the conventions, better syntax information.
This commit is contained in:
@@ -35,6 +35,31 @@ namespace argument_parser::conventions::implementations {
|
||||
std::string gnu_argument_convention::long_prec() const {
|
||||
return "--";
|
||||
}
|
||||
|
||||
std::vector<convention_features> gnu_argument_convention::get_features() const {
|
||||
return {}; // no fallback allowed
|
||||
}
|
||||
|
||||
std::string gnu_argument_convention::make_help_text(std::string const &short_arg, std::string const &long_arg,
|
||||
bool requires_value) const {
|
||||
std::string res = "";
|
||||
if (short_arg != "-" && short_arg != "") {
|
||||
res += short_prec() + short_arg;
|
||||
if (requires_value) {
|
||||
res += " <value>";
|
||||
}
|
||||
}
|
||||
if (long_arg != "-" && long_arg != "") {
|
||||
if (!res.empty()) {
|
||||
res += ", ";
|
||||
}
|
||||
res += long_prec() + long_arg;
|
||||
if (requires_value) {
|
||||
res += " <value>";
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
} // namespace argument_parser::conventions::implementations
|
||||
|
||||
namespace argument_parser::conventions::implementations {
|
||||
@@ -72,4 +97,29 @@ namespace argument_parser::conventions::implementations {
|
||||
return "--";
|
||||
}
|
||||
|
||||
std::string gnu_equal_argument_convention::make_help_text(std::string const &short_arg, std::string const &long_arg,
|
||||
bool requires_value) const {
|
||||
std::string res = "";
|
||||
if (short_arg != "-" && short_arg != "") {
|
||||
res += short_prec() + short_arg;
|
||||
if (requires_value) {
|
||||
res += "=<value>";
|
||||
}
|
||||
}
|
||||
if (long_arg != "-" && long_arg != "") {
|
||||
if (!res.empty()) {
|
||||
res += ", ";
|
||||
}
|
||||
res += long_prec() + long_arg;
|
||||
if (requires_value) {
|
||||
res += "=<value>";
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<convention_features> gnu_equal_argument_convention::get_features() const {
|
||||
return {}; // no fallback allowed
|
||||
}
|
||||
} // namespace argument_parser::conventions::implementations
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "windows_argument_convention.hpp"
|
||||
#include "base_convention.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace argument_parser::conventions::implementations {
|
||||
@@ -49,6 +50,33 @@ namespace argument_parser::conventions::implementations {
|
||||
return "/";
|
||||
}
|
||||
|
||||
std::string windows_argument_convention::make_help_text(std::string const &short_arg, std::string const &long_arg,
|
||||
bool requires_value) const {
|
||||
std::string res = "";
|
||||
if (short_arg != "-" && short_arg != "") {
|
||||
res += short_prec() + short_arg;
|
||||
if (requires_value) {
|
||||
res += " <value>";
|
||||
}
|
||||
}
|
||||
|
||||
if (long_arg != "-" && long_arg != "") {
|
||||
if (!res.empty()) {
|
||||
res += ", ";
|
||||
}
|
||||
res += long_prec() + long_arg;
|
||||
if (requires_value) {
|
||||
res += " <value>";
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<convention_features> windows_argument_convention::get_features() const {
|
||||
return {convention_features::ALLOW_LONG_TO_SHORT_FALLBACK,
|
||||
convention_features::ALLOW_SHORT_TO_LONG_FALLBACK}; // interchangable
|
||||
}
|
||||
} // namespace argument_parser::conventions::implementations
|
||||
|
||||
namespace argument_parser::conventions::implementations {
|
||||
@@ -101,4 +129,35 @@ namespace argument_parser::conventions::implementations {
|
||||
std::string windows_kv_argument_convention::long_prec() const {
|
||||
return "/";
|
||||
}
|
||||
|
||||
std::string windows_kv_argument_convention::make_help_text(std::string const &short_arg,
|
||||
std::string const &long_arg, bool requires_value) const {
|
||||
std::string res = "";
|
||||
if (short_arg != "-" && short_arg != "") {
|
||||
res += short_prec() + short_arg;
|
||||
if (requires_value) {
|
||||
res += "=<value>";
|
||||
res += ", " + short_prec() + short_arg;
|
||||
res += ":<value>";
|
||||
}
|
||||
}
|
||||
|
||||
if (long_arg != "-" && long_arg != "") {
|
||||
if (!res.empty()) {
|
||||
res += ", ";
|
||||
}
|
||||
res += long_prec() + long_arg;
|
||||
if (requires_value) {
|
||||
res += "=<value>"
|
||||
", " +
|
||||
long_prec() + long_arg + ":<value>";
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<convention_features> windows_kv_argument_convention::get_features() const {
|
||||
return {convention_features::ALLOW_LONG_TO_SHORT_FALLBACK,
|
||||
convention_features::ALLOW_SHORT_TO_LONG_FALLBACK}; // interchangable
|
||||
}
|
||||
} // namespace argument_parser::conventions::implementations
|
||||
Reference in New Issue
Block a user