mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
CommandLine: adds --json flag as a shortcut for enabling JSON output
This commit is contained in:
@@ -63,6 +63,17 @@
|
||||
},
|
||||
"default": "default"
|
||||
}
|
||||
},
|
||||
{
|
||||
"long": "json",
|
||||
"short": "j",
|
||||
"arg": {
|
||||
"type": "bool",
|
||||
"default": false,
|
||||
"optional": true
|
||||
},
|
||||
"desc": "Enable or disable JSON output",
|
||||
"remark": "Shortcut for `--format json`"
|
||||
}
|
||||
],
|
||||
"Config": [
|
||||
|
||||
+26
-20
@@ -549,6 +549,26 @@ static void printVersion()
|
||||
printf("%s %s%s%s (%s)\n", result->projectName, result->version, result->versionTweak, result->debugMode ? "-debug" : "", result->architecture);
|
||||
}
|
||||
|
||||
static void enableJsonOutput(bool enable)
|
||||
{
|
||||
if (!enable)
|
||||
{
|
||||
if (instance.state.resultDoc)
|
||||
{
|
||||
yyjson_mut_doc_free(instance.state.resultDoc);
|
||||
instance.state.resultDoc = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!instance.state.resultDoc)
|
||||
{
|
||||
instance.state.resultDoc = yyjson_mut_doc_new(NULL);
|
||||
yyjson_mut_doc_set_root(instance.state.resultDoc, yyjson_mut_arr(instance.state.resultDoc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void parseCommand(FFdata* data, char* key, char* value)
|
||||
{
|
||||
if(ffStrEqualsIgnCase(key, "-h") || ffStrEqualsIgnCase(key, "--help"))
|
||||
@@ -640,29 +660,15 @@ static void parseCommand(FFdata* data, char* key, char* value)
|
||||
generateConfigFile(true, value, true);
|
||||
else if(ffStrEqualsIgnCase(key, "-c") || ffStrEqualsIgnCase(key, "--config"))
|
||||
optionParseConfigFile(data, key, value);
|
||||
else if(ffStrEqualsIgnCase(key, "-j") || ffStrEqualsIgnCase(key, "--json"))
|
||||
enableJsonOutput(ffOptionParseBoolean(value));
|
||||
else if(ffStrEqualsIgnCase(key, "--format"))
|
||||
{
|
||||
switch (ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
|
||||
{ "default", 0},
|
||||
{ "json", 1 },
|
||||
enableJsonOutput(!!ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
|
||||
{ "default", false},
|
||||
{ "json", true },
|
||||
{},
|
||||
}))
|
||||
{
|
||||
case 0:
|
||||
if (instance.state.resultDoc)
|
||||
{
|
||||
yyjson_mut_doc_free(instance.state.resultDoc);
|
||||
instance.state.resultDoc = NULL;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!instance.state.resultDoc)
|
||||
{
|
||||
instance.state.resultDoc = yyjson_mut_doc_new(NULL);
|
||||
yyjson_mut_doc_set_root(instance.state.resultDoc, yyjson_mut_arr(instance.state.resultDoc));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}));
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user