feat(cli): add a simplified command line over the logic layer
The window needs a display, which kept the package manager out of a script and off a headless machine. The command line runs the same operations through AppCore, before any widget exists, so providers, the pacman lock, the journal and the history behave exactly as in the window. Refs #22.
This commit is contained in:
11 files changed
+1055
-5
No files matched your search
+45
-4
@@ -1,15 +1,57 @@
|
||||
#include <QApplication>
|
||||
#include <QCoreApplication>
|
||||
#include <QLoggingCategory>
|
||||
#include <QStringList>
|
||||
#include <QTimer>
|
||||
|
||||
#include "app-settings.h"
|
||||
#include "cli-application.h"
|
||||
#include "cli-command.h"
|
||||
#include "language-manager.h"
|
||||
#include "log-manager.h"
|
||||
#include "main-window.h"
|
||||
#include "update-manager.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// The arguments as the command-line grammar wants them: program name excluded.
|
||||
QStringList commandLineArguments(int argc, char* argv[]) {
|
||||
QStringList arguments;
|
||||
if (argc > 1) arguments.reserve(argc - 1);
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
arguments << QString::fromLocal8Bit(argv[i]);
|
||||
}
|
||||
return arguments;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
const QStringList arguments = commandLineArguments(argc, argv);
|
||||
|
||||
// The command line is decided before any widget exists: `pacmanager install
|
||||
// vlc` has to work on a machine with no display, so it runs on a
|
||||
// QCoreApplication and never builds the window.
|
||||
if (cli::isCliInvocation(arguments)) {
|
||||
QCoreApplication app(argc, argv);
|
||||
app.setApplicationName("PacManager");
|
||||
app.setApplicationVersion(UpdateManager::currentVersion());
|
||||
app.setOrganizationName("Freebuff");
|
||||
|
||||
LogManager::installQtMessageHandler();
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("app"),
|
||||
QCoreApplication::translate("main", "session démarrée (v%1)")
|
||||
.arg(UpdateManager::currentVersion()));
|
||||
|
||||
const int code = cli::run(arguments);
|
||||
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("app"),
|
||||
QCoreApplication::translate("main", "session terminée (code %1)").arg(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
QApplication app(argc, argv);
|
||||
app.setApplicationName("PacManager");
|
||||
app.setApplicationVersion(UpdateManager::currentVersion());
|
||||
@@ -44,10 +86,9 @@ int main(int argc, char* argv[]) {
|
||||
// Files the desktop handed over ("Ouvrir avec PacManager", the desktop
|
||||
// entry declares %U): installed once the event loop runs, so the window is
|
||||
// visible and any dialog has a parent.
|
||||
const QStringList fileArgs = app.arguments().mid(1);
|
||||
if (!fileArgs.isEmpty()) {
|
||||
QTimer::singleShot(0, &window, [&window, fileArgs] {
|
||||
window.installLocalFiles(fileArgs);
|
||||
if (!arguments.isEmpty()) {
|
||||
QTimer::singleShot(0, &window, [&window, arguments] {
|
||||
window.installLocalFiles(arguments);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user