[Home]Program Name - Program Options Suggestion

BOOST WIKI | RecentChanges | Preferences | Page List | Links List

program_name() and %progname%

Back to Suggestions - program options library


It would be very handy if the program_options provided a static function which returned the program name -- from argv[0] -- but stripped of any path or extraneous .exe. That is, a name which is suitable for inclusion in a usage message. Suppose this were provided as program_options::program_name(). Then, you could make a nice usage message, with:

    options_description desc("Usage: " + program_name() + " <args> OPTIONS\n"
                             "        OPTIONS");

It would be even nicer to have a predefined tag to represent the program name, like:

    options_description desc("Usage: %progname% <args> OPTIONS\n"
                             "        OPTIONS");

If something like this is provided already, then demonstrate it in the sample code.

    - People/Chuck Messenger


Personally, I think it's better to hardcode the program name -- which should be some canonical name. On UNIX, the same program can be invoked under miriad different names and I believe it should produce the same help message in all cases. Also, it's easy to put version string in hardcoded string, but you can't extract it from argv[0]. Are you sure this feature is really necessary?

    - People/Vladimir Prus


One way or another, the program name needs to be part of the usage message. And, I think program_options should generate a usage message. So, program_options needs some way to spit out the program name.

Now, given those fundamentals, the question is, how can you hardcode the program name? You need to let the user design their own usage message, clearly. Could you illustrate how you'd hardcode the name?

And, I could agree with you about the UNIX case -- where you can access the canonical name. Seems reasonable.

    - People/Chuck Messenger


Why not:

    options_description desc("Usage: my_program 1.0.1 <args> OPTIONS\n"
                             "        OPTIONS");

   - People/Vladimir Prus


Because the name of the program might well change! I hate having to remember to make changes in multiple places -- it invariably leads to errors.

It's a natural thing for program_options to take care of, since you're passing in argv[0] anyway...

    - People/Chuck Messenger

BOOST WIKI | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited May 22, 2003 12:17 pm (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers