Fastfetch: support -c none; remove --load-user-config

This commit is contained in:
李通洲
2023-11-16 16:41:08 +08:00
parent f8ba138b8d
commit 998193b014
5 changed files with 29 additions and 18 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ typedef struct FFdata
{
FFstrbuf structure;
FFlist customValues; // List of FFCustomValue
bool loadUserConfig;
bool configLoaded;
} FFdata;
bool ffParseModuleOptions(const char* key, const char* value);
+2 -3
View File
@@ -17,10 +17,9 @@ Informative options:
--print-structure: Print the default structure
Config options:
-c, --config <config>: Load a config file or preset (+)
-c, --config <config>: Specify the config file or preset to be loaded. If `none`, disable futher config loading (+)
--gen-config <?path>: Generate a config file (or print it if <path> is `-`), with options specified in the command line (if any)
--gen-config-force <?path>: Generate a config file. Overwrite the existing one
--load-user-config <?bool>: Set if user config should be loaded. Default is true if env-var `NO_CONFIG` is not set
General options:
--thread <?bool>: Use separate threads to send HTTP requests
@@ -184,4 +183,4 @@ Module specific options:
Parsing is not case sensitive. E.g. "--lib-PCI" is equal to "--Lib-Pci"
If a value starts with a ?, it is optional. "true" will be used if not set.
A (+) at the end indicates that more help can be printed with --help <option>
All options can be made permanent with command `fastfetch <options> --migrate-config`
All options can be made permanent with command `fastfetch <options> --gen-config`
+18 -10
View File
@@ -345,18 +345,29 @@ static void generateConfigFile(bool force, const char* filePath)
static void optionParseConfigFile(FFdata* data, const char* key, const char* value)
{
if (data->configLoaded)
{
fprintf(stderr, "Error: only one config file can be loaded\n");
exit(413);
}
data->configLoaded = true;
if(value == NULL)
{
fprintf(stderr, "Error: usage: %s <file>\n", key);
fprintf(stderr, "Error: usage: %s <config>\n", key);
exit(413);
}
uint32_t fileNameLen = (uint32_t) strlen(value);
if(fileNameLen == 0)
{
fprintf(stderr, "Error: usage: %s <file>\n", key);
fprintf(stderr, "Error: usage: %s <config>\n", key);
exit(413);
}
if (ffStrEqualsIgnCase(value, "none"))
return;
bool isJsonConfig = fileNameLen > strlen(".jsonc") && strcasecmp(value + fileNameLen - strlen(".jsonc"), ".jsonc") == 0;
//Try to load as an absolute path
@@ -498,8 +509,8 @@ static void parseCommand(FFdata* data, char* key, char* value)
generateConfigFile(false, value);
else if(ffStrEqualsIgnCase(key, "--gen-config-force"))
generateConfigFile(true, value);
else if(ffStrEqualsIgnCase(key, "--load-user-config"))
data->loadUserConfig = ffOptionParseBoolean(value);
else if(ffStrEqualsIgnCase(key, "-c") || ffStrEqualsIgnCase(key, "--load-config") || ffStrEqualsIgnCase(key, "--config"))
optionParseConfigFile(data, key, value);
else if(ffStrEqualsIgnCase(key, "--format"))
{
switch (ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
@@ -535,10 +546,7 @@ static void parseCommand(FFdata* data, char* key, char* value)
static void parseOption(FFdata* data, const char* key, const char* value)
{
if(ffStrEqualsIgnCase(key, "-c") || ffStrEqualsIgnCase(key, "--load-config") || ffStrEqualsIgnCase(key, "--config"))
optionParseConfigFile(data, key, value);
else if(ffStrEqualsIgnCase(key, "--set") || ffStrEqualsIgnCase(key, "--set-keyless"))
if(ffStrEqualsIgnCase(key, "--set") || ffStrEqualsIgnCase(key, "--set-keyless"))
{
FF_STRBUF_AUTO_DESTROY customValueStr = ffStrbufCreate();
ffOptionParseString(key, value, &customValueStr);
@@ -725,11 +733,11 @@ int main(int argc, char** argv)
FFdata data = {
.structure = ffStrbufCreate(),
.customValues = ffListCreate(sizeof(FFCustomValue)),
.loadUserConfig = !getenv("NO_CONFIG"),
.configLoaded = false,
};
parseArguments(&data, argc, argv, parseCommand);
if(data.loadUserConfig)
if(!data.configLoaded && !getenv("NO_CONFIG"))
parseConfigFiles(&data);
parseArguments(&data, argc, argv, (void*) parseOption);