aboutsummaryrefslogtreecommitdiffhomepage
path: root/hyprpm/src/main.cpp
blob: c6f083a8eec0e2f8d703f54c0de3f2593f07c06b (plain)
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
#include "progress/CProgressBar.hpp"
#include "helpers/Colors.hpp"
#include "core/PluginManager.hpp"

#include <iostream>
#include <vector>
#include <string>
#include <chrono>
#include <thread>

int main(int argc, char** argv, char** envp) {
    std::vector<std::string> ARGS{argc};
    for (int i = 0; i < argc; ++i) {
        ARGS[i] = std::string{argv[i]};
    }

    if (ARGS.size() < 2) {
        std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args.\n";
        return 1;
    }

    g_pPluginManager = std::make_unique<CPluginManager>();

    if (ARGS[1] == "add") {
        if (ARGS.size() < 3) {
            std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for add.\n";
            return 1;
        }

        return g_pPluginManager->addNewPluginRepo(ARGS[2]) ? 0 : 1;
    } else if (ARGS[1] == "remove") {
        if (ARGS.size() < 3) {
            std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for remove.\n";
            return 1;
        }

        return g_pPluginManager->removePluginRepo(ARGS[2]) ? 0 : 1;
    } else if (ARGS[1] == "update") {
        bool headersValid = g_pPluginManager->headersValid() == HEADERS_OK;
        bool headers      = g_pPluginManager->updateHeaders();
        if (headers)
            g_pPluginManager->updatePlugins(!headersValid);
    } else if (ARGS[1] == "enable") {
        if (ARGS.size() < 3) {
            std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for enable.\n";
            return 1;
        }

        if (!g_pPluginManager->enablePlugin(ARGS[2])) {
            std::cerr << Colors::RED << "✖" << Colors::RESET << " Couldn't enable plugin (missing?)\n";
            return 1;
        }

        g_pPluginManager->ensurePluginsLoadState();
    } else if (ARGS[1] == "disable") {
        if (ARGS.size() < 3) {
            std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for disable.\n";
            return 1;
        }

        if (!g_pPluginManager->disablePlugin(ARGS[2])) {
            std::cerr << Colors::RED << "✖" << Colors::RESET << " Couldn't disable plugin (missing?)\n";
            return 1;
        }

        g_pPluginManager->ensurePluginsLoadState();
    } else if (ARGS[1] == "load") {
        g_pPluginManager->ensurePluginsLoadState();
    }

    return 0;
}