1+ #include < cstring>
2+ #include " libcufetch/common.hh"
3+ #include " libs/switch_fnv1a.hpp"
14#include " pluginManager.hpp"
25#include " stateManager.hpp"
6+
37#if (!__has_include("version.h"))
48#error "version.h not found, please generate it with ./scripts/generateVersion.sh"
59#else
812
913#include " getopt_port/getopt.h"
1014
15+ enum {
16+ INSTALL,
17+ REMOVE,
18+ LIST
19+ };
20+
21+ static struct operations_t
22+ {
23+ int name;
24+ std::vector<std::string> args;
25+ } op;
26+
1127static void version ()
1228{
1329 fmt::print (
@@ -28,7 +44,7 @@ Manage plugins for customfetch.
2844NOTE: the operations must be the first argument to pass
2945
3046OPERATIONS:
31- add - Add a new plugin repository. Takes as an argument the git url to be cloned.
47+ install - Install a new plugin repository. Takes as an argument the git url to be cloned.
3248
3349GENERAL OPTIONS
3450 -h, --help Print this help menu.
@@ -56,6 +72,28 @@ static bool parseargs(int argc, char* argv[])
5672
5773 // clang-format on
5874 optind = 1 ;
75+ for (int i = 1 ; i < argc; ++i)
76+ {
77+ if (strncmp (argv[i], " install" , 7 ) == 0 || strncmp (argv[i], " i" , 1 ) == 0 )
78+ {
79+ op.name = INSTALL;
80+ optind++;
81+ break ;
82+ }
83+ if (strncmp (argv[i], " list" , 4 ) == 0 || strncmp (argv[i], " l" , 1 ) == 0 )
84+ {
85+ op.name = LIST;
86+ optind++;
87+ break ;
88+ }
89+ if (strncmp (argv[i], " remove" , 6 ) == 0 || strncmp (argv[i], " r" , 1 ) == 0 )
90+ {
91+ op.name = REMOVE;
92+ optind++;
93+ break ;
94+ }
95+ }
96+
5997 while ((opt = getopt_long (argc, argv, optstring, opts, &option_index)) != -1 )
6098 {
6199 switch (opt)
@@ -69,6 +107,9 @@ static bool parseargs(int argc, char* argv[])
69107 }
70108 }
71109
110+ for (int i = optind; i < argc; ++i)
111+ op.args .push_back (argv[i]);
112+
72113 return true ;
73114}
74115
@@ -79,7 +120,18 @@ int main(int argc, char* argv[])
79120
80121 fs::create_directories ({ getHomeCacheDir () / " cufetchpm" / " plugins" });
81122 StateManager state;
82- PluginManager man (std::move (state));
83- man.add_repo_plugins (argv[2 ]);
123+ PluginManager plugin_manager (std::move (state));
124+ switch (op.name )
125+ {
126+ case INSTALL:
127+ {
128+ if (op.args .size () != 1 )
129+ die (" Please provide a singular git url repository" );
130+ plugin_manager.add_repo_plugins (op.args [0 ]); break ;
131+ }
132+ default :
133+ warn (" Not yet implemented" );
134+ }
135+
84136 return 0 ;
85137}
0 commit comments