Taeung Song | 30862f2 | 2015-11-17 22:53:21 +0900 | [diff] [blame] | 1 | /* |
| 2 | * builtin-config.c |
| 3 | * |
| 4 | * Copyright (C) 2015, Taeung Song <treeze.taeung@gmail.com> |
| 5 | * |
| 6 | */ |
| 7 | #include "builtin.h" |
| 8 | |
| 9 | #include "perf.h" |
| 10 | |
| 11 | #include "util/cache.h" |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame^] | 12 | #include <subcmd/parse-options.h> |
Taeung Song | 30862f2 | 2015-11-17 22:53:21 +0900 | [diff] [blame] | 13 | #include "util/util.h" |
| 14 | #include "util/debug.h" |
| 15 | |
| 16 | static const char * const config_usage[] = { |
| 17 | "perf config [options]", |
| 18 | NULL |
| 19 | }; |
| 20 | |
| 21 | enum actions { |
| 22 | ACTION_LIST = 1 |
| 23 | } actions; |
| 24 | |
| 25 | static struct option config_options[] = { |
| 26 | OPT_SET_UINT('l', "list", &actions, |
| 27 | "show current config variables", ACTION_LIST), |
| 28 | OPT_END() |
| 29 | }; |
| 30 | |
| 31 | static int show_config(const char *key, const char *value, |
| 32 | void *cb __maybe_unused) |
| 33 | { |
| 34 | if (value) |
| 35 | printf("%s=%s\n", key, value); |
| 36 | else |
| 37 | printf("%s\n", key); |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused) |
| 43 | { |
| 44 | int ret = 0; |
| 45 | |
| 46 | argc = parse_options(argc, argv, config_options, config_usage, |
| 47 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 48 | |
| 49 | switch (actions) { |
| 50 | case ACTION_LIST: |
| 51 | if (argc) { |
| 52 | pr_err("Error: takes no arguments\n"); |
| 53 | parse_options_usage(config_usage, config_options, "l", 1); |
| 54 | } else { |
| 55 | ret = perf_config(show_config, NULL); |
| 56 | if (ret < 0) |
| 57 | pr_err("Nothing configured, " |
| 58 | "please check your ~/.perfconfig file\n"); |
| 59 | } |
| 60 | break; |
| 61 | default: |
| 62 | usage_with_options(config_usage, config_options); |
| 63 | } |
| 64 | |
| 65 | return ret; |
| 66 | } |