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 * configset_get_value -> returns value with the highest priority for the entered key
20 * from a config_set constructed from files entered as arguments.
22 * configset_get_value_multi -> returns value_list for the entered key sorted in
23 * ascending order of priority from a config_set
24 * constructed from files entered as arguments.
28 * To print the value with highest priority for key "foo.bAr Baz.rock":
29 * test-config get_value "foo.bAr Baz.rock"
34 int main(int argc
, char **argv
)
38 const struct string_list
*strptr
;
40 git_configset_init(&cs
);
43 fprintf(stderr
, "Please, provide a command name on the command-line\n");
45 } else if (argc
== 3 && !strcmp(argv
[1], "get_value")) {
46 if (!git_config_get_value(argv
[2], &v
)) {
53 printf("Value not found for \"%s\"\n", argv
[2]);
56 } else if (argc
== 3 && !strcmp(argv
[1], "get_value_multi")) {
57 strptr
= git_config_get_value_multi(argv
[2]);
59 for (i
= 0; i
< strptr
->nr
; i
++) {
60 v
= strptr
->items
[i
].string
;
68 printf("Value not found for \"%s\"\n", argv
[2]);
71 } else if (argc
== 3 && !strcmp(argv
[1], "get_int")) {
72 if (!git_config_get_int(argv
[2], &val
)) {
76 printf("Value not found for \"%s\"\n", argv
[2]);
79 } else if (argc
== 3 && !strcmp(argv
[1], "get_bool")) {
80 if (!git_config_get_bool(argv
[2], &val
)) {
84 printf("Value not found for \"%s\"\n", argv
[2]);
87 } else if (!strcmp(argv
[1], "configset_get_value")) {
88 for (i
= 3; i
< argc
; i
++) {
90 if ((err
= git_configset_add_file(&cs
, argv
[i
]))) {
91 fprintf(stderr
, "Error (%d) reading configuration file %s.\n", err
, argv
[i
]);
95 if (!git_configset_get_value(&cs
, argv
[2], &v
)) {
102 printf("Value not found for \"%s\"\n", argv
[2]);
105 } else if (!strcmp(argv
[1], "configset_get_value_multi")) {
106 for (i
= 3; i
< argc
; i
++) {
108 if ((err
= git_configset_add_file(&cs
, argv
[i
]))) {
109 fprintf(stderr
, "Error (%d) reading configuration file %s.\n", err
, argv
[i
]);
113 strptr
= git_configset_get_value_multi(&cs
, argv
[2]);
115 for (i
= 0; i
< strptr
->nr
; i
++) {
116 v
= strptr
->items
[i
].string
;
124 printf("Value not found for \"%s\"\n", argv
[2]);
129 die("%s: Please check the syntax and the function name", argv
[0]);
132 git_configset_clear(&cs
);
136 git_configset_clear(&cs
);
140 git_configset_clear(&cs
);