File: main_app.cpp

package info (click to toggle)
codelite 17.0.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 136,244 kB
  • sloc: cpp: 491,547; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 804; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (94 lines) | stat: -rw-r--r-- 2,506 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "cl_standard_paths.h"
#include "csConfig.h"
#include "file_logger.h"
#include "main_app.h"
#include <SocketAPI/clSocketServer.h>
#include <iostream>
#include <wx/filename.h>
#include <wx/crt.h>

IMPLEMENT_APP_CONSOLE(MainApp)

static const wxCmdLineEntryDesc cmdLineDesc[] = {
    { wxCMD_LINE_SWITCH, "v", "version", "Print current version", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
    { wxCMD_LINE_SWITCH, "h", "help", "Print usage", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
    { wxCMD_LINE_PARAM, "c", "command", "command", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
    { wxCMD_LINE_PARAM, "o", "options", "options", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
    { wxCMD_LINE_NONE }
};

MainApp::MainApp()
    : m_manager(nullptr)
{
}

MainApp::~MainApp() {}

int MainApp::OnExit()
{
    clDEBUG() << "Going down";
    wxDELETE(m_manager);
    return TRUE;
}

bool MainApp::OnInit()
{
    SetAppName("codelite-cli");

    // Make sure that the 'local' folder exists
    wxFileName::Mkdir(clStandardPaths::Get().GetUserDataDir(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);

    // Mainly needed for Windows
    clSocketBase::Initialize();

    // Allocate the manager class
    m_manager = new csManager();

    wxCmdLineParser parser(wxAppConsole::argc, wxAppConsole::argv);
    DoParseCommandLine(parser);

    // Open the log file
    FileLogger::OpenLog("codelite-cli.log", FileLogger::Developer);

    // Startup
    return m_manager->Startup();
}

bool MainApp::DoParseCommandLine(wxCmdLineParser& parser)
{
    parser.SetDesc(cmdLineDesc);
    if(parser.Parse(false) != 0) {
        return false;
    }
    
    m_manager->GetCommand() = parser.GetParam(0);
    m_manager->GetOptions() = parser.GetParam(1);
    
    if(parser.Found("v")) {
        // Print version and exit
        std::cout << "codelite-cli v1.0" << std::endl;
        m_manager->SetExitNow(true);
        return true;
    }
    
    if(parser.Found("h")) {
        m_manager->SetExitNow(true);
        PrintUsage(parser);
        return true;
    }

    if(m_manager->GetCommand().IsEmpty()) {
        // Try to fetch the options from the INI file
        m_manager->LoadCommandFromINI();
        if(m_manager->GetCommand().IsEmpty()) {
            return false;
        }
    }
    return true;
}

void MainApp::PrintUsage(const wxCmdLineParser& parser)
{
    wxString usageString = parser.GetUsageString();
    std::cerr << usageString.mb_str(wxConvUTF8).data() << std::endl;
}