11#include < cstdlib>
2+ #include < filesystem>
23
4+ #include " fmt/base.h"
5+ #include " fmt/ranges.h"
36#include " libcufetch/common.hh"
47#include " pluginManager.hpp"
58#include " stateManager.hpp"
@@ -19,8 +22,6 @@ enum Ops
1922 LIST
2023} op = NONE;
2124
22- static std::vector<std::string> arguments;
23-
2425void version ()
2526{
2627 fmt::print (
@@ -37,14 +38,14 @@ void help(int invalid_opt = false)
3738{
3839 fmt::print (R"( Usage: cufetchpm <command> [options]
3940Manage plugins for customfetch.
40- NOTE: the operations must be the first argument to pass
4141
4242Commands:
43- install [options] <repo> Install a new plugin repository. Takes as an argument the git url to be cloned.
43+ install [options] <repo/path>... Install one or more plugin sources from a Git repo or local path.
44+ help <command> Show help for a specific command.
4445
4546Global options:
46- -h, --help Print this help menu .
47- -V, --version Print version and other infos about the build.
47+ -h, --help Show this help message .
48+ -V, --version Show version and build information .
4849
4950)" );
5051
@@ -53,11 +54,17 @@ Global options:
5354
5455void help_install (int invalid_opt = false )
5556{
56- fmt::print (R"( Usage: cufetchpm install [options] <repo>
57+ fmt::print (R"( Usage: cufetchpm install [options] <repo/path>...
58+
59+ Install one or more plugin sources. If a given argument exists on disk,
60+ it is treated as a local directory. Otherwise, it is treated as a Git
61+ repository URL and will be cloned.
62+
63+ All plugins found within the source will be installed.
5764
5865Options:
59- -f, --force Force installation
60- -h, --help Show help for install
66+ -f, --force Force installation, even if already installed.
67+ -h, --help Show help for this command.
6168)" );
6269
6370 std::exit (invalid_opt);
@@ -66,19 +73,18 @@ void help_install(int invalid_opt = false)
6673void help_list (int invalid_opt = false )
6774{
6875 fmt::print (R"( Usage: cufetchpm list [options]
76+ List all installed plugins.
6977
7078Options:
71- -v, --verbose Show detailed info
72- -h, --help Show help for list
79+ -v, --verbose Show detailed plugin information.
80+ -h, --help Show help for this command.
7381)" );
7482
7583 std::exit (invalid_opt);
7684}
7785
7886bool parse_install_args (int argc, char * argv[])
7987{
80- bool force = false ;
81-
8288 // clang-format off
8389 const struct option long_opts[] = {
8490 {" force" , no_argument, nullptr , ' f' },
@@ -92,25 +98,23 @@ bool parse_install_args(int argc, char* argv[])
9298 {
9399 switch (opt)
94100 {
95- case ' f' : force = true ; break ;
101+ case ' f' : options. install_force = true ; break ;
96102 case ' h' : help_install (EXIT_SUCCESS); break ;
97103 case ' ?' : help_install (EXIT_FAILURE); break ;
98104 }
99105 }
100106
101107 for (int i = optind; i < argc; ++i)
102- arguments.emplace_back (argv[i]);
108+ options. arguments .emplace_back (argv[i]);
103109
104- if (arguments.empty ())
105- die (" install: no repositories given" );
110+ if (options. arguments .empty ())
111+ die (" install: no repositories/paths given" );
106112
107113 return true ;
108114}
109115
110116bool parse_list_args (int argc, char * argv[])
111117{
112- bool verbose = false ;
113-
114118 // clang-format off
115119 const struct option long_opts[] = {
116120 {" verbose" , no_argument, nullptr , ' v' },
@@ -124,7 +128,7 @@ bool parse_list_args(int argc, char* argv[])
124128 {
125129 switch (opt)
126130 {
127- case ' v' : verbose = true ; break ;
131+ case ' v' : options. list_verbose = true ; break ;
128132 case ' h' : help_list (EXIT_SUCCESS); break ;
129133 case ' ?' : help_list (EXIT_FAILURE); break ;
130134 }
@@ -206,15 +210,42 @@ int main(int argc, char* argv[])
206210 return -1 ;
207211
208212 fs::create_directories ({ getHomeCacheDir () / " cufetchpm" / " plugins" });
213+ fs::create_directories ({ getConfigDir () / " plugins" });
214+ StateManager state;
209215 switch (op)
210216 {
211217 case INSTALL:
212218 {
213- if (arguments.size () < 1 )
219+ if (options. arguments .size () < 1 )
214220 die (" Please provide a singular git url repository" );
215- StateManager state;
216221 PluginManager plugin_manager (std::move (state));
217- plugin_manager.add_repo_plugins (arguments[0 ]);
222+ for (const std::string& arg : options.arguments )
223+ {
224+ if (arg.find (" ://" ) == arg.npos && fs::exists (arg))
225+ plugin_manager.build_plugins (arg);
226+ else
227+ plugin_manager.add_repo_plugins (arg);
228+ }
229+ break ;
230+ }
231+ case LIST:
232+ {
233+ for (const manifest_t & manifest : state.get_all_repos ())
234+ {
235+ fmt::println (" \033 [1;32mRepository:\033 [0m {}" , manifest.name );
236+ fmt::println (" \033 [1;33mURL:\033 [0m {}" , manifest.url );
237+ fmt::println (" \033 [1;34mPlugins:" );
238+ for (const plugin_t & plugin : manifest.plugins )
239+ {
240+ fmt::println (" \033 [1;34m - {}\033 [0m" , plugin.name );
241+ fmt::println (" \t\033 [1;35mDescription:\033 [0m {}" , plugin.description );
242+ fmt::println (" \t\033 [1;36mAuthor(s):\033 [0m {}" , fmt::join (plugin.authors , " , " ));
243+ fmt::println (" \t\033 [1;38;2;220;220;220mLicense(s):\033 [0m {}" , fmt::join (plugin.licenses , " , " ));
244+ fmt::println (" \t\033 [1;38;2;144;238;144mPrefixe(s):\033 [0m {}" , fmt::join (plugin.prefixes , " , " ));
245+ fmt::print (" \n " );
246+ }
247+ fmt::print (" \033 [0m" );
248+ }
218249 break ;
219250 }
220251 default : warn (" uh?" );
0 commit comments