Replies: 2 comments 5 replies
-
Here's a hacky solution: #include <sharg/all.hpp>
int main(int argc, char const ** argv)
{
// Or std::string if argv is `char` instead of `const char`
static constexpr std::string_view call_help{"-h"};
static constexpr std::string_view call_version{"--version"};
std::vector const custom_argv = [&]()
{
std::vector result(argv, argv + argc);
assert(argc > 0 && result.size() == static_cast<size_t>(argc));
if (argc >= 2)
{
if (result[1] == std::string_view{"help"})
{
result[1] = call_help.data();
}
else if (result[1] == std::string_view{"version"})
{
result[1] = call_version.data();
}
}
return result;
}();
sharg::parser parser{"my_app", argc, custom_argv.data()};
parser.add_subsection("My Section");
int val{};
parser.add_option(val, sharg::config{.short_id = 'i', .long_id = "int", .description = "My description."});
parser.parse();
return 0;
} We should at least discuss adding a C++-API for the parser constructor. Currently, the container's value_type needs to be |
Beta Was this translation helpful? Give feedback.
4 replies
-
With #239, we accept So the hack would now be: #include <sharg/all.hpp>
int main(int argc, char const ** argv)
{
std::vector<std::string> arguments{argv, argv + argc};
if (arguments.size() > 1u)
{
auto & first_argument = arguments[1];
if (first_argument == "help")
{
first_argument = "--help";
}
else if (first_argument == "version")
{
first_argument = "--version";
}
}
sharg::parser parser{"my_app", arguments};
parser.add_subsection("My Section");
int val{};
parser.add_option(val, sharg::config{.short_id = 'i', .long_id = "int", .description = "My description."});
parser.parse();
return 0;
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I need to be able to show the help page on
./myapp help
in addition to (or instead of)./myapp --help
. How would I currently achieve that? Ideally there would be a nice mechanism for this and similar situations (e.g../myapp version
), but I would also take a hacky solution 😬Beta Was this translation helpful? Give feedback.
All reactions