Search code examples
c++cconsoleusage-message

What is the best way to include a "help" message in a console application?


I am writing a console application which is rapidly gaining many command line arguments and flags. For this reason I want the user to be able to access a description of these flags and what purpose they serve.

There are several possible solutions I can think of

  • I could write a README file and just stick it in the same directory as the executable. Advantages are it is simple and portable, but disadvantage is that it is easy for someone to remove/edit the file.
  • I could stick the whole message in a variable inside my program and print this to the screen when the user types mycmd --help or something similar. Advantages, stays with executable and not editable, disadvantage is in code since I would have something like that below floating around.

    const char[] helpmsg = "Line1\n"
                           "Line2\n"
                           "...\n"
                           "LineN\n";
    
  • I could write a man entry for my program but this isn't very portable as the application will be used pretty equally on Windows and Linux.

I'm aware the question is probably a matter of taste but I was just curious if there are any other solutions which I haven't thought of that people have used in the past.

Ideally it would be something which is easy for the developer (at the moment me) to edit and keep updated but where others cannot really mess with it.


Solution

  • Consider using the boost program options library.