4 * Copyright (C) 2015, Taeung Song <treeze.taeung@gmail.com>
11 #include "util/cache.h"
12 #include <subcmd/parse-options.h>
13 #include "util/util.h"
14 #include "util/debug.h"
16 static bool use_system_config
, use_user_config
;
18 static const char * const config_usage
[] = {
19 "perf config [<file-option>] [options]",
27 static struct option config_options
[] = {
28 OPT_SET_UINT('l', "list", &actions
,
29 "show current config variables", ACTION_LIST
),
30 OPT_BOOLEAN(0, "system", &use_system_config
, "use system config file"),
31 OPT_BOOLEAN(0, "user", &use_user_config
, "use user config file"),
35 static int show_config(const char *key
, const char *value
,
36 void *cb __maybe_unused
)
39 printf("%s=%s\n", key
, value
);
46 int cmd_config(int argc
, const char **argv
, const char *prefix __maybe_unused
)
49 char *user_config
= mkpath("%s/.perfconfig", getenv("HOME"));
51 argc
= parse_options(argc
, argv
, config_options
, config_usage
,
52 PARSE_OPT_STOP_AT_NON_OPTION
);
54 if (use_system_config
&& use_user_config
) {
55 pr_err("Error: only one config file at a time\n");
56 parse_options_usage(config_usage
, config_options
, "user", 0);
57 parse_options_usage(NULL
, config_options
, "system", 0);
61 if (use_system_config
)
62 config_exclusive_filename
= perf_etc_perfconfig();
63 else if (use_user_config
)
64 config_exclusive_filename
= user_config
;
69 pr_err("Error: takes no arguments\n");
70 parse_options_usage(config_usage
, config_options
, "l", 1);
72 ret
= perf_config(show_config
, NULL
);
74 const char * config_filename
= config_exclusive_filename
;
75 if (!config_exclusive_filename
)
76 config_filename
= user_config
;
77 pr_err("Nothing configured, "
78 "please check your %s \n", config_filename
);
83 usage_with_options(config_usage
, config_options
);