Ticket #5935: 00-5935-mythwelcome-showusage.2.patch

File 00-5935-mythwelcome-showusage.2.patch, 4.0 KB (added by Matthew Wire <devel@…>, 15 years ago)
  • mythtv/programs/mythwelcome/main.cpp

     
    2020#include "mythuihelper.h"
    2121#include "lcddevice.h"
    2222#include "myththemebase.h"
     23#include "mythcommandlineparser.h"
    2324
    2425#include "libmythtv/tv.h"
    2526
     
    4142    REG_KEY("Welcome", "STARTSETUP", "Start Mythtv-Setup", "");
    4243}
    4344
     45void showUsage(const MythCommandLineParser &cmdlineparser)
     46{
     47    QString    help  = cmdlineparser.GetHelpString(false);
     48    QByteArray ahelp = help.toLocal8Bit();
     49   
     50    QString binname = "mythwelcome";
     51
     52    extern const char *myth_source_version;
     53    extern const char *myth_source_path;
     54
     55    VERBOSE(VB_IMPORTANT, QString("%1 version: %2 [%3] www.mythtv.org")
     56                            .arg(binname)
     57                            .arg(myth_source_path)
     58                            .arg(myth_source_version));
     59   
     60    cerr << "Valid options are: " << endl <<
     61            "-v or --verbose debug-level    Use '-v help' for level info" << endl <<
     62            "-s or --setup                  Run setup for the mythshutdown program" << endl <<
     63            "-l or --logfile filename       Writes STDERR and STDOUT messages to filename" << endl <<
     64            ahelp.constData() <<
     65            endl;
     66   
     67}
     68
    4469int main(int argc, char **argv)
    4570{
    4671    bool bShowSettings = false;
    4772
    48     QApplication a(argc, argv);
     73    bool cmdline_err;
     74   
     75    MythCommandLineParser cmdline(
     76        kCLPOverrideSettingsFile |
     77        kCLPOverrideSettings     |
     78        kCLPQueryVersion);
    4979
    50     gContext = NULL;
    51     gContext = new MythContext(MYTH_BINARY_VERSION);
    52     if (!gContext->Init())
     80    for (int argpos = 0; argpos < argc; ++argpos)
    5381    {
    54         VERBOSE(VB_IMPORTANT, "mythwelcome: Could not initialize myth context. "
    55                         "Exiting.");
    56         return FRONTEND_EXIT_NO_MYTHCONTEXT;
    57     }
     82        if (cmdline.PreParse(argc, argv, argpos, cmdline_err))
     83        {
     84            if (cmdline_err)
     85                return BACKEND_EXIT_INVALID_CMDLINE;
    5886
    59     if (!MSqlQuery::testDBConnection())
    60     {
    61         VERBOSE(VB_IMPORTANT, "mythwelcome: Could not open the database. "
    62                         "Exiting.");
    63         return -1;
     87            if (cmdline.WantsToExit())
     88                return BACKEND_EXIT_OK;
     89        }
    6490    }
     91   
     92    QApplication a(argc, argv);
    6593
    6694    // Check command line arguments
    6795    for (int argpos = 1; argpos < a.argc(); ++argpos)
     
    110138                return FRONTEND_EXIT_INVALID_CMDLINE;
    111139            }
    112140        }
     141        else if (cmdline.Parse(a.argc(), a.argv(), argpos, cmdline_err))
     142        {
     143            if (cmdline_err)
     144                return BACKEND_EXIT_INVALID_CMDLINE;
     145
     146            if (cmdline.WantsToExit())
     147                return BACKEND_EXIT_OK;
     148        }
    113149        else
    114150        {
    115             cerr << "Invalid argument: " << a.argv()[argpos] << endl <<
    116                     "Valid options are: " << endl <<
    117                     "-v or --verbose debug-level    Use '-v help' for level info" << endl <<
    118                     "-s or --setup                  Run setup for the mythshutdown program" << endl <<
    119                     "-l or --logfile filename       Writes STDERR and STDOUT messages to filename" << endl;
     151            showUsage(cmdline);
    120152            return FRONTEND_EXIT_INVALID_CMDLINE;
    121153        }
    122154    }
    123155
     156    gContext = NULL;
     157    gContext = new MythContext(MYTH_BINARY_VERSION);
     158    if (!gContext->Init())
     159    {
     160        VERBOSE(VB_IMPORTANT, "mythwelcome: Could not initialize myth context. "
     161                        "Exiting.");
     162        return FRONTEND_EXIT_NO_MYTHCONTEXT;
     163    }
     164
     165    if (!MSqlQuery::testDBConnection())
     166    {
     167        VERBOSE(VB_IMPORTANT, "mythwelcome: Could not open the database. "
     168                        "Exiting.");
     169        return -1;
     170    }
     171
    124172    if (logfile != "")
    125173    {
    126174        if (!log_rotate(true))