Skip to content

Commit 44b1b46

Browse files
committed
cufetchpm: add arguments (ultra WIP)
1 parent 7425e00 commit 44b1b46

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

cufetchpm/include/pluginManager.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef _PLUGIN_MANAGER_HPP_
22
#define _PLUGIN_MANAGER_HPP_
33

4-
#include <array>
54
#include <filesystem>
65
#include <string>
76
#include <string_view>
@@ -10,7 +9,7 @@
109
#include "stateManager.hpp"
1110
#include "util.hpp"
1211

13-
constexpr std::array<std::string_view, 1> dependencies = { "git" }; // expand in the future, maybe
12+
constexpr std::string_view dependencies[] = { "git" }; // expand in the future, maybe
1413

1514
#define BOLD_COLOR(x) (fmt::emphasis::bold | fmt::fg(fmt::rgb(x)))
1615

cufetchpm/src/main.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,79 @@
1+
#include <getopt.h>
2+
13
#include "pluginManager.hpp"
24
#include "stateManager.hpp"
5+
#if (!__has_include("version.h"))
6+
#error "version.h not found, please generate it with ./scripts/generateVersion.sh"
7+
#else
8+
#include "version.h"
9+
#endif
10+
11+
static void version()
12+
{
13+
fmt::print(
14+
"cufetchpm {} built from branch '{}' at {} commit '{}' ({}).\n"
15+
"Date: {}\n"
16+
"Tag: {}\n",
17+
VERSION, GIT_BRANCH, GIT_DIRTY, GIT_COMMIT_HASH, GIT_COMMIT_MESSAGE, GIT_COMMIT_DATE, GIT_TAG);
18+
19+
// if only everyone would not return error when querying the program version :(
20+
std::exit(EXIT_SUCCESS);
21+
}
22+
23+
static void help(int invalid_opt = false)
24+
{
25+
constexpr std::string_view help(
26+
R"(Usage: cufetchpm [OPERATION] [ARGUMENTS] [OPTIONS]...
27+
Manage plugins for customfetch.
28+
NOTE: the operations must be the first argument to pass
29+
30+
-h, --help Print this help menu.
31+
-V, --version Print version and other infos about the build.
32+
33+
OPERATIONS:
34+
add - Add a new plugin repository. Takes as an argument the git url to be cloned.
35+
)");
36+
37+
fmt::print("{}", help);
38+
fmt::print("\n");
39+
std::exit(invalid_opt);
40+
}
41+
42+
static bool parseargs(int argc, char* argv[])
43+
{
44+
int opt = 0;
45+
int option_index = 0;
46+
const char *optstring = "-Vh";
47+
static const struct option opts[] = {
48+
{"version", no_argument, 0, 'V'},
49+
{"help", no_argument, 0, 'h'},
50+
51+
{0,0,0,0}
52+
};
53+
54+
/* parse operation */
55+
optind = 0;
56+
while ((opt = getopt_long(argc, argv, optstring, opts, &option_index)) != -1)
57+
{
58+
switch (opt)
59+
{
60+
case 0: break;
61+
case '?': help(EXIT_FAILURE); break;
62+
63+
case 'V': version(); break;
64+
case 'h': help(); break;
65+
default: return false;
66+
}
67+
}
68+
69+
return true;
70+
}
371

472
int main(int argc, char* argv[])
573
{
74+
if (!parseargs(argc, argv))
75+
return -1;
76+
677
std::filesystem::create_directories({ getHomeCacheDir() / "cufetchpm" / "plugins" });
778
StateManager state;
879
PluginManager man(std::move(state));

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void help(bool invalid_opt = false)
124124
{
125125
constexpr std::string_view help(
126126
R"(Usage: customfetch [OPTIONS]...
127-
A command-line, GUI, and Android widget system information tool (like neofetch) focused on customizability and performance.
127+
A command-line, GUI app, and Android widget system information tool (like neofetch) focused on customizability and performance.
128128
129129
NOTE: Boolean flags [<BOOL>] accept: "true", 1, "enable", or empty. Any other value is treated as false.
130130

0 commit comments

Comments
 (0)