Merge branch 'jk/maint-do-not-feed-stdin-to-tests'
[git] / test-credential.c
1 #include "cache.h"
2 #include "credential.h"
3 #include "string-list.h"
4
5 static const char usage_msg[] =
6 "test-credential <fill|approve|reject> [helper...]";
7
8 int main(int argc, const char **argv)
9 {
10         const char *op;
11         struct credential c = CREDENTIAL_INIT;
12         int i;
13
14         op = argv[1];
15         if (!op)
16                 usage(usage_msg);
17         for (i = 2; i < argc; i++)
18                 string_list_append(&c.helpers, argv[i]);
19
20         if (credential_read(&c, stdin) < 0)
21                 die("unable to read credential from stdin");
22
23         if (!strcmp(op, "fill")) {
24                 credential_fill(&c);
25                 if (c.username)
26                         printf("username=%s\n", c.username);
27                 if (c.password)
28                         printf("password=%s\n", c.password);
29         }
30         else if (!strcmp(op, "approve"))
31                 credential_approve(&c);
32         else if (!strcmp(op, "reject"))
33                 credential_reject(&c);
34         else
35                 usage(usage_msg);
36
37         return 0;
38 }