mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-03-02 01:40:16 -05:00
feat: support -c option to specified config file
This commit is contained in:
parent
a2902a469b
commit
1ffdc1ef38
3 changed files with 22 additions and 4 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include <ctype.h>
|
||||
#include <libgen.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
|
@ -2307,7 +2308,14 @@ void parse_config_file(Config *config, const char *file_path) {
|
|||
// Relative path
|
||||
|
||||
const char *mangoconfig = getenv("MANGOCONFIG");
|
||||
if (mangoconfig && mangoconfig[0] != '\0') {
|
||||
|
||||
if (cli_config_path) {
|
||||
char *config_path = strdup(cli_config_path);
|
||||
char *config_dir = dirname(config_path);
|
||||
snprintf(full_path, sizeof(full_path), "%s/%s", config_dir,
|
||||
file_path + 1);
|
||||
free(config_path);
|
||||
} else if (mangoconfig && mangoconfig[0] != '\0') {
|
||||
snprintf(full_path, sizeof(full_path), "%s/%s", mangoconfig,
|
||||
file_path + 1);
|
||||
} else {
|
||||
|
|
@ -3040,7 +3048,9 @@ void parse_config(void) {
|
|||
const char *mangoconfig = getenv("MANGOCONFIG");
|
||||
|
||||
// 如果 MANGOCONFIG 环境变量不存在或为空,则使用 HOME 环境变量
|
||||
if (!mangoconfig || mangoconfig[0] == '\0') {
|
||||
if (cli_config_path) {
|
||||
snprintf(filename, sizeof(filename), "%s", cli_config_path);
|
||||
} else if (!mangoconfig || mangoconfig[0] == '\0') {
|
||||
// 获取当前用户家目录
|
||||
const char *homedir = getenv("HOME");
|
||||
if (!homedir) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue