MCPcopy Create free account
hub / github.com/TheAssassin/AppImageLauncher / main

Function main

src/cli/cli_main.cpp:16–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14using namespace appimagelauncher::cli::commands;
15
16int main(int argc, char** argv) {
17 // we don't have support for UI (and don't want that), so let's tell shared to not display dialogs
18 setenv("_FORCE_HEADLESS", "1", 1);
19
20 QCoreApplication app(argc, argv);
21
22 std::ostringstream version;
23 version << "version " << APPIMAGELAUNCHER_VERSION << " "
24 << "(git commit " << APPIMAGELAUNCHER_GIT_COMMIT << "), built on "
25 << APPIMAGELAUNCHER_BUILD_DATE;
26 QCoreApplication::setApplicationVersion(QString::fromStdString(version.str()));
27
28 QCommandLineParser parser;
29
30 parser.addPositionalArgument("<command>", "Command to run (see help for more information");
31 parser.addPositionalArgument("[...]", "command-specific additional arguments");
32 parser.addHelpOption();
33 parser.addVersionOption();
34
35 parser.process(app);
36
37 auto posArgs = parser.positionalArguments();
38
39 if (posArgs.isEmpty()) {
40 qerr() << parser.helpText().toStdString().c_str() << endl;
41
42 qerr() << "Available commands:" << endl;
43 qerr() << " integrate Integrate AppImages passed as commandline arguments" << endl;
44 qerr() << " unintegrate Unintegrate AppImages passed as commandline arguments" << endl;
45
46 return 2;
47 }
48
49 auto commandName = posArgs.front();
50 posArgs.pop_front();
51
52 try {
53 auto command = CommandFactory::getCommandByName(commandName);
54 command->exec(posArgs);
55 } catch (const CommandNotFoundError& e) {
56 qerr() << e.what() << endl;
57 return 1;
58 } catch (const InvalidArgumentsError& e) {
59 qerr() << "Invalid arguments: " << e.what() << endl;
60 return 3;
61 } catch (const UsageError& e) {
62 qerr() << "Usage error: " << e.what() << endl;
63 return 3;
64 }
65
66 return 0;
67}

Callers

nothing calls this directly

Calls 1

execMethod · 0.45

Tested by

no test coverage detected