aboutsummaryrefslogtreecommitdiffhomepage
path: root/hyprpm/src/main.cpp
blob: 02131df347e8235f8ec454cb48e82fee5af18e80 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "progress/CProgressBar.hpp"
#include "helpers/Colors.hpp"
#include "core/PluginManager.hpp"

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

const std::string HELP = R"#(┏ hyprpm, a Hyprland Plugin Manager

┣ add [url]              → Install a new plugin repository from git
┣ remove [url/name]      → Remove an installed plugin repository
┣ enable [name]          → Enable a plugin
┣ disable [name]         → Disable a plugin
┣ update                 → Check and update all plugins if needed
┣ load                   → Load hyprpm state. Ensure all enabled plugins are loaded.
┣ list                   → List all installed plugins

)#";

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 || ARGS[1] == "--help" || ARGS[1] == "-h") {
        std::cout << HELP;
        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);
            g_pPluginManager->ensurePluginsLoadState();
        }
    } 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();
    } else if (ARGS[1] == "list") {
        g_pPluginManager->listAllPlugins();
    } else {
        std::cout << HELP;
        return 1;
    }

    return 0;
}