argparse icon indicating copy to clipboard operation
argparse copied to clipboard

program_name can be problematic

Open rowlesmr opened this issue 1 year ago • 1 comments

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.

rowlesmr avatar Aug 23 '22 13:08 rowlesmr