Skip to content

Commit 7bcb015

Browse files
committed
Help: print command specific help message
1 parent 02bdcd3 commit 7bcb015

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

src/data/help.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@
592592
"long": "size-max-prefix",
593593
"desc": "Set the largest binary prefix to use when formatting sizes",
594594
"arg": {
595-
"type": "str",
595+
"type": "enum",
596596
"enum": {
597597
"B": "Bytes",
598598
"kB": "KiB",
@@ -611,7 +611,7 @@
611611
"long": "temperature-unit",
612612
"desc": "Set the unit of the temperature",
613613
"arg": {
614-
"type": "str",
614+
"type": "enum",
615615
"enum": {
616616
"C": "Celsius",
617617
"F": "Fahrenheit",
@@ -1241,7 +1241,7 @@
12411241
"long": "opengl-library",
12421242
"desc": "Set the OpenGL context creation library to use",
12431243
"arg": {
1244-
"type": "str",
1244+
"type": "enum",
12451245
"enum": {
12461246
"auto": "Auto detection",
12471247
"egl": "EGL",
@@ -1277,7 +1277,7 @@
12771277
"long": "colors-symbol",
12781278
"desc": "Set the symbol to be printed by Colors module",
12791279
"arg": {
1280-
"type": "str",
1280+
"type": "enum",
12811281
"enum": {
12821282
"block": "███",
12831283
"circle": "",

src/fastfetch.c

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,72 @@ static bool printSpecificCommandHelp(const char* command)
155155
assert(longKey);
156156
if (ffStrEqualsIgnCase(command, yyjson_get_str(longKey)))
157157
{
158-
printf("Usage: --%s\n", command);
158+
puts(yyjson_get_str(yyjson_obj_get(flagObj, "desc")));
159+
160+
printf("%10s: ", "Usage");
161+
yyjson_val* shortKey = yyjson_obj_get(flagObj, "short");
162+
if (shortKey)
163+
{
164+
if (!instance.config.display.pipe)
165+
fputs("\e[1m", stdout);
166+
printf("-%s", yyjson_get_str(shortKey));
167+
if (!instance.config.display.pipe)
168+
fputs("\e[m", stdout);
169+
fputs(", ", stdout);
170+
}
171+
if (!instance.config.display.pipe)
172+
fputs("\e[1m", stdout);
173+
printf("--%s", yyjson_get_str(longKey));
174+
if (!instance.config.display.pipe)
175+
fputs("\e[m", stdout);
176+
177+
yyjson_val* argObj = yyjson_obj_get(flagObj, "arg");
178+
if (argObj)
179+
{
180+
yyjson_val* typeKey = yyjson_obj_get(argObj, "type");
181+
assert(typeKey);
182+
yyjson_val* optionalKey = yyjson_obj_get(argObj, "optional");
183+
bool optional = optionalKey && yyjson_get_bool(optionalKey);
184+
putchar(' ');
185+
if (!instance.config.display.pipe)
186+
fputs("\e[3m", stdout);
187+
printf("<%s%s>", optional ? "?" : "", yyjson_get_str(typeKey));
188+
if (!instance.config.display.pipe)
189+
fputs("\e[m", stdout);
190+
putchar('\n');
191+
192+
yyjson_val* defaultKey = yyjson_obj_get(argObj, "default");
193+
if (defaultKey)
194+
{
195+
if (ffStrEqualsIgnCase(yyjson_get_str(typeKey), "structure"))
196+
printf("%10s: %s\n", "Default", FASTFETCH_DATATEXT_STRUCTURE);
197+
else if (yyjson_is_bool(defaultKey))
198+
printf("%10s: %s\n", "Default", yyjson_get_bool(defaultKey) ? "true" : "false");
199+
else if (yyjson_is_num(defaultKey))
200+
printf("%10s: %g\n", "Default", yyjson_get_num(defaultKey));
201+
else if (yyjson_is_str(defaultKey))
202+
printf("%10s: %s\n", "Default", yyjson_get_str(defaultKey));
203+
else
204+
printf("%10s: Unknown\n", "Default");
205+
}
206+
207+
yyjson_val* enumKey = yyjson_obj_get(argObj, "enum");
208+
if (enumKey)
209+
{
210+
printf("%10s:\n", "Options");
211+
yyjson_val *optKey, *optVal;
212+
size_t optIdx, optMax;
213+
yyjson_obj_foreach(enumKey, optIdx, optMax, optKey, optVal)
214+
printf("%12s: %s\n", yyjson_get_str(optKey), yyjson_get_str(optVal));
215+
}
216+
}
217+
else
218+
putchar('\n');
219+
220+
yyjson_val* remarkKey = yyjson_obj_get(flagObj, "remark");
221+
if (remarkKey)
222+
printf("%10s: %s\n", "Remark", yyjson_get_str(remarkKey));
223+
159224
return true;
160225
}
161226
}

0 commit comments

Comments
 (0)