Ticket #7662: help3.patch

File help3.patch, 4.4 KB (added by doug@…, 14 years ago)
  • libs/libmyth/mythcommandlineparser.h

     
    2424class MPUBLIC MythCommandLineParser
    2525{
    2626  public:
    27     MythCommandLineParser(int things_to_parse);
     27    MythCommandLineParser(int things_to_parse, void (*helpFunc)(const MythCommandLineParser&) = 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);
     
    4040    bool    WantsToExit(void) const { return wantsToExit; }
    4141
    4242  private:
     43    QString GetHelpStringInternal(bool with_header) const;
     44
    4345    int                   parseTypes;
    4446
    4547    QMap<QString,QString> settingsOverride;
     
    4850    QString               geometry;
    4951
    5052    bool                  wantsToExit;
     53    void              (*helpFunction)(const MythCommandLineParser &);
    5154};
  • 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)(const MythCommandLineParser&)) :
    1414    parseTypes(things_to_parse),
    1515    display(QString::null), geometry(QString::null),
    16     wantsToExit(false)
     16    wantsToExit(false), helpFunction(helpFunc)
    1717{
    1818}
    1919
     
    100100              !strcmp(argv[argpos],"--help") ||
    101101              !strcmp(argv[argpos],"--usage")))
    102102    {
    103         QString help = GetHelpString(false);
     103        QString help = GetHelpStringInternal(false);
    104104        QByteArray ahelp = help.toLocal8Bit();
    105105        cerr << ahelp.constData();
    106106        wantsToExit = true;
     
    276276    }
    277277}
    278278
     279QString MythCommandLineParser::GetHelpStringInternal(bool with_header) const
     280{
     281    if (helpFunction)
     282    {
     283        helpFunction(*this);
     284        return "";
     285    }
     286
     287    return GetHelpString(with_header);
     288}
     289
    279290QString MythCommandLineParser::GetHelpString(bool with_header) const
    280291{
    281292    QString str;
  • programs/mythfrontend/main.cpp

     
    11191119        kCLPDisplay              |
    11201120#endif // USING_X11
    11211121        kCLPExtra                |
    1122         kCLPGeometry);
     1122        kCLPGeometry             |
     1123        kCLPHelp,
     1124        ShowUsage);
    11231125
     1126    // This will catch any help lines (e.g. --h) and display them
    11241127    for (int argpos = 1; argpos < argc; ++argpos)
    11251128    {
    11261129        if (cmdline.PreParse(argc, argv, argpos, cmdline_err))
     
    11601163
    11611164    for (int argpos = 1; argpos < a.argc(); ++argpos)
    11621165    {
    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") ||
     1166        if (!strcmp(a.argv()[argpos],"--prompt") ||
    11711167                 !strcmp(a.argv()[argpos],"-p" ))
    11721168        {
    11731169            bPromptForBackend = true;
     
    13071303                !strcmp(a.argv()[argpos],"--help") ||
    13081304                !strcmp(a.argv()[argpos],"--usage")))
    13091305                cerr << "Invalid argument: " << a.argv()[argpos] << endl;
    1310             ShowUsage(cmdline);
    1311             return FRONTEND_EXIT_INVALID_CMDLINE;
     1306                ShowUsage(cmdline);
     1307                return FRONTEND_EXIT_INVALID_CMDLINE;
    13121308        }
    13131309    }
    13141310    settingsOverride = cmdline.GetSettingsOverride();
  • programs/mythwelcome/main.cpp

     
    7777    MythCommandLineParser cmdline(
    7878        kCLPOverrideSettingsFile |
    7979        kCLPOverrideSettings     |
    80         kCLPQueryVersion);
     80        kCLPQueryVersion         |
     81        kCLPHelp,
     82        showUsage);
    8183
    8284    for (int argpos = 0; argpos < argc; ++argpos)
    8385    {