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"
15 #include "util/config.h"
17 static bool use_system_config
, use_user_config
;
19 static const char * const config_usage
[] = {
20 "perf config [<file-option>] [options]",
28 static struct option config_options
[] = {
29 OPT_SET_UINT('l', "list", &actions
,
30 "show current config variables", ACTION_LIST
),
31 OPT_BOOLEAN(0, "system", &use_system_config
, "use system config file"),
32 OPT_BOOLEAN(0, "user", &use_user_config
, "use user config file"),
36 static int show_config(struct perf_config_set
*set
)
38 struct perf_config_section
*section
;
39 struct perf_config_item
*item
;
44 perf_config_set__for_each_entry(set
, section
, item
) {
45 char *value
= item
->value
;
48 printf("%s.%s=%s\n", section
->name
,
55 int cmd_config(int argc
, const char **argv
, const char *prefix __maybe_unused
)
58 struct perf_config_set
*set
;
59 char *user_config
= mkpath("%s/.perfconfig", getenv("HOME"));
61 argc
= parse_options(argc
, argv
, config_options
, config_usage
,
62 PARSE_OPT_STOP_AT_NON_OPTION
);
64 if (use_system_config
&& use_user_config
) {
65 pr_err("Error: only one config file at a time\n");
66 parse_options_usage(config_usage
, config_options
, "user", 0);
67 parse_options_usage(NULL
, config_options
, "system", 0);
71 if (use_system_config
)
72 config_exclusive_filename
= perf_etc_perfconfig();
73 else if (use_user_config
)
74 config_exclusive_filename
= user_config
;
77 * At only 'config' sub-command, individually use the config set
78 * because of reinitializing with options config file location.
80 set
= perf_config_set__new();
89 pr_err("Error: takes no arguments\n");
90 parse_options_usage(config_usage
, config_options
, "l", 1);
92 ret
= show_config(set
);
94 const char * config_filename
= config_exclusive_filename
;
95 if (!config_exclusive_filename
)
96 config_filename
= user_config
;
97 pr_err("Nothing configured, "
98 "please check your %s \n", config_filename
);
103 usage_with_options(config_usage
, config_options
);
106 perf_config_set__delete(set
);