forked from fastfetch-cli/fastfetch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotfilemanager.c
More file actions
114 lines (95 loc) · 3.69 KB
/
Copy pathdotfilemanager.c
File metadata and controls
114 lines (95 loc) · 3.69 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "common/printing.h"
#include "common/jsonconfig.h"
#include "detection/libc/libc.h"
#include "detection/dotfilemanager/dotfilemanager.h"
#include "modules/dotfilemanager/dotfilemanager.h"
#include "util/stringUtils.h"
void ffPrintDotfileManager(FFDotfileManagerOptions* options)
{
FFDotfileManagerResult result = {
.name = ffStrbufCreate(),
};
const char* error = ffDetectDotfileManager(&result);
if (error)
{
ffPrintError(FF_DOTFILEMANAGER_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
}
if (options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_DOTFILEMANAGER_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&result.name, stdout);
putchar('\n');
}
else
{
FF_PRINT_FORMAT_CHECKED(FF_DOTFILEMANAGER_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){
FF_FORMAT_ARG(result.name, "name"),
}));
}
ffStrbufDestroy(&result.name);
}
bool ffParseDotfileManagerCommandOptions(FFDotfileManagerOptions* options, const char* key, const char* value)
{
const char* subKey = ffOptionTestPrefix(key, FF_DOTFILEMANAGER_MODULE_NAME);
if (!subKey) return false;
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
return true;
return false;
}
void ffParseDotfileManagerJsonObject(FFDotfileManagerOptions* options, yyjson_val* module)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
ffPrintError(FF_DOTFILEMANAGER_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", key);
}
}
void ffGenerateDotfileManagerJsonConfig(FFDotfileManagerOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
__attribute__((__cleanup__(ffDestroyDotfileManagerOptions))) FFDotfileManagerOptions defaultOptions;
ffInitDotfileManagerOptions(&defaultOptions);
ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
}
void ffGenerateDotfileManagerJsonResult(FF_MAYBE_UNUSED FFDotfileManagerOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFDotfileManagerResult result = {
.name = ffStrbufCreate(),
};
const char* error = ffDetectDotfileManager(&result);
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "name", &result.name);
ffStrbufDestroy(&result.name);
}
static FFModuleBaseInfo ffModuleInfo = {
.name = FF_DOTFILEMANAGER_MODULE_NAME,
.description = "Print information about the dotfile manager",
.parseCommandOptions = (void*) ffParseDotfileManagerCommandOptions,
.parseJsonObject = (void*) ffParseDotfileManagerJsonObject,
.printModule = (void*) ffPrintDotfileManager,
.generateJsonResult = (void*) ffGenerateDotfileManagerJsonResult,
.generateJsonConfig = (void*) ffGenerateDotfileManagerJsonConfig,
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
{"Name", "name"},
}))
};
void ffInitDotfileManagerOptions(FFDotfileManagerOptions* options)
{
options->moduleInfo = ffModuleInfo;
ffOptionInitModuleArg(&options->moduleArgs, "");
}
void ffDestroyDotfileManagerOptions(FFDotfileManagerOptions* options)
{
ffOptionDestroyModuleArg(&options->moduleArgs);
}