argparse
argparse copied to clipboard
program_name can be problematic
program_name
is taken from the zeroth argument. If the program is called with a full (or partial) path, then this ends up in program_name
, and then into the help text and other places.
It can be fixed by changing Args::parse
:
#include <filesystem>
program_name = std::filesystem::path(argv[0]).stem().string();
This creates a path
object from the zeroth argument, and then grabs the filename (without extension) and puts the string representation of that into program_name
. This is also cross-platform compatible.