argparse icon indicating copy to clipboard operation
argparse copied to clipboard

program_name can be problematic

Open rowlesmr opened this issue 3 years 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

I'm happy to do a PR (and also for some other things).

How do you want them submitted? against a new branch for each one?

rowlesmr avatar Aug 23 '22 15:08 rowlesmr

Hi @rowlesmr , thank you very much for raising this issue, this is indeed a problem when the absolute path is used. With the latest update I've used your suggestion to extract the program name. Thanks you very much!

morrisfranken avatar Mar 20 '23 21:03 morrisfranken