2 #include "string-list.h"
5 * This program exposes the C API of the configuration mechanism
6 * as a set of simple commands in order to facilitate testing.
8 * Reads stdin and prints result of command to stdout:
10 * get_value -> prints the value with highest priority for the entered key
12 * get_value_multi -> prints all values for the entered key in increasing order
15 * get_int -> print integer value for the entered key or die
17 * get_bool -> print bool value for the entered key or die
19 * get_string -> print string value for the entered key or die
21 * configset_get_value -> returns value with the highest priority for the entered key
22 * from a config_set constructed from files entered as arguments.
24 * configset_get_value_multi -> returns value_list for the entered key sorted in
25 * ascending order of priority from a config_set
26 * constructed from files entered as arguments.
30 * To print the value with highest priority for key "foo.bAr Baz.rock":
31 * test-config get_value "foo.bAr Baz.rock"
36 int main(int argc
, char **argv
)
40 const struct string_list
*strptr
;
43 setup_git_directory();
45 git_configset_init(&cs
);
48 fprintf(stderr
, "Please, provide a command name on the command-line\n");
50 } else if (argc
== 3 && !strcmp(argv
[1], "get_value")) {
51 if (!git_config_get_value(argv
[2], &v
)) {
58 printf("Value not found for \"%s\"\n", argv
[2]);
61 } else if (argc
== 3 && !strcmp(argv
[1], "get_value_multi")) {
62 strptr
= git_config_get_value_multi(argv
[2]);
64 for (i
= 0; i
< strptr
->nr
; i
++) {
65 v
= strptr
->items
[i
].string
;
73 printf("Value not found for \"%s\"\n", argv
[2]);
76 } else if (argc
== 3 && !strcmp(argv
[1], "get_int")) {
77 if (!git_config_get_int(argv
[2], &val
)) {
81 printf("Value not found for \"%s\"\n", argv
[2]);
84 } else if (argc
== 3 && !strcmp(argv
[1], "get_bool")) {
85 if (!git_config_get_bool(argv
[2], &val
)) {
89 printf("Value not found for \"%s\"\n", argv
[2]);
92 } else if (argc
== 3 && !strcmp(argv
[1], "get_string")) {
93 if (!git_config_get_string_const(argv
[2], &v
)) {
97 printf("Value not found for \"%s\"\n", argv
[2]);
100 } else if (!strcmp(argv
[1], "configset_get_value")) {
101 for (i
= 3; i
< argc
; i
++) {
103 if ((err
= git_configset_add_file(&cs
, argv
[i
]))) {
104 fprintf(stderr
, "Error (%d) reading configuration file %s.\n", err
, argv
[i
]);
108 if (!git_configset_get_value(&cs
, argv
[2], &v
)) {
115 printf("Value not found for \"%s\"\n", argv
[2]);
118 } else if (!strcmp(argv
[1], "configset_get_value_multi")) {
119 for (i
= 3; i
< argc
; i
++) {
121 if ((err
= git_configset_add_file(&cs
, argv
[i
]))) {
122 fprintf(stderr
, "Error (%d) reading configuration file %s.\n", err
, argv
[i
]);
126 strptr
= git_configset_get_value_multi(&cs
, argv
[2]);
128 for (i
= 0; i
< strptr
->nr
; i
++) {
129 v
= strptr
->items
[i
].string
;
137 printf("Value not found for \"%s\"\n", argv
[2]);
142 die("%s: Please check the syntax and the function name", argv
[0]);
145 git_configset_clear(&cs
);
149 git_configset_clear(&cs
);
153 git_configset_clear(&cs
);