Ticket #7662: help2.patch

File help2.patch, 3.8 KB (added by doug@…, 11 years ago)

patch version 2

  • libs/libmyth/mythcommandlineparser.h

     
    2424class MPUBLIC MythCommandLineParser
    2525{
    2626  public:
    27     MythCommandLineParser(int things_to_parse);
     27    MythCommandLineParser(int things_to_parse, void (*helpFunc)(QString) = NULL);
    2828
    2929    bool PreParse(int argc, const char * const * argv, int &argpos, bool &err);
    3030    bool Parse(int argc, const char * const * argv, int &argpos, bool &err);
     
    4848    QString               geometry;
    4949
    5050    bool                  wantsToExit;
     51    void              (*helpFunction)(QString);
    5152};
  • libs/libmyth/mythcommandlineparser.cpp

     
    1010#include "mythverbose.h"
    1111#include "mythversion.h"
    1212
    13 MythCommandLineParser::MythCommandLineParser(int things_to_parse) :
     13MythCommandLineParser::MythCommandLineParser(int things_to_parse, void (*helpFunc)(QString)) :
    1414    parseTypes(things_to_parse),
    1515    display(QString::null), geometry(QString::null),
    16     wantsToExit(false)
     16    wantsToExit(false), helpFunction(helpFunc)
    1717{
    1818}
    1919
     
    281281    QString str;
    282282    QTextStream msg(&str, QIODevice::WriteOnly);
    283283
    284     if (with_header)
     284    // help function is always without header
     285    if (!helpFunction && with_header)
    285286        msg << "Valid options are: " << endl;
    286287
    287288    if (parseTypes & kCLPDisplay)
     
    346347
    347348    msg.flush();
    348349
     350    if (helpFunction)
     351    {
     352       helpFunction(str);
     353       return "";
     354    }
     355
    349356    return str;
    350357}
  • programs/mythfrontend/main.cpp

     
    10031003        MythDB::DBError("CleanupMyOldInUsePrograms", query);
    10041004}
    10051005
    1006 void ShowUsage(const MythCommandLineParser &cmdlineparser)
     1006void ShowUsage(QString helptext)
    10071007{
    1008     QString    help  = cmdlineparser.GetHelpString(false);
    1009     QByteArray ahelp = help.toLocal8Bit();
     1008    QByteArray ahelp = helptext.toLocal8Bit();
    10101009
    10111010    cerr << "Valid options are: " << endl <<
    10121011            "-l or --logfile filename       Writes STDERR and STDOUT messages to filename" << endl <<
     
    11191118        kCLPDisplay              |
    11201119#endif // USING_X11
    11211120        kCLPExtra                |
    1122         kCLPGeometry);
     1121        kCLPGeometry             |
     1122        kCLPHelp,
     1123        ShowUsage);
    11231124
     1125    // This will catch any help lines (e.g. --h) and display them
    11241126    for (int argpos = 1; argpos < argc; ++argpos)
    11251127    {
    11261128        if (cmdline.PreParse(argc, argv, argpos, cmdline_err))
     
    11601162
    11611163    for (int argpos = 1; argpos < a.argc(); ++argpos)
    11621164    {
    1163         if (!strcmp(a.argv()[argpos],"-h") ||
    1164                 !strcmp(a.argv()[argpos],"--help") ||
    1165                 !strcmp(a.argv()[argpos],"--usage"))
    1166         {
    1167             ShowUsage(cmdline);
    1168             return FRONTEND_EXIT_OK;
    1169         }
    1170         else if (!strcmp(a.argv()[argpos],"--prompt") ||
     1165        if (!strcmp(a.argv()[argpos],"--prompt") ||
    11711166                 !strcmp(a.argv()[argpos],"-p" ))
    11721167        {
    11731168            bPromptForBackend = true;
     
    13071302                !strcmp(a.argv()[argpos],"--help") ||
    13081303                !strcmp(a.argv()[argpos],"--usage")))
    13091304                cerr << "Invalid argument: " << a.argv()[argpos] << endl;
    1310             ShowUsage(cmdline);
    1311             return FRONTEND_EXIT_INVALID_CMDLINE;
     1305                cerr << "Try: --help " << endl;
     1306                return FRONTEND_EXIT_INVALID_CMDLINE;
    13121307        }
    13131308    }
    13141309    settingsOverride = cmdline.GetSettingsOverride();