add 'git credential' plumbing command
[git/git.git] / builtin / credential.c
1 #include "git-compat-util.h"
2 #include "credential.h"
3 #include "builtin.h"
4
5 static const char usage_msg[] =
6 "git credential [fill|approve|reject]";
7
8 int cmd_credential(int argc, const char **argv, const char *prefix)
9 {
10 const char *op;
11 struct credential c = CREDENTIAL_INIT;
12
13 op = argv[1];
14 if (!op)
15 usage(usage_msg);
16
17 if (credential_read(&c, stdin) < 0)
18 die("unable to read credential from stdin");
19
20 if (!strcmp(op, "fill")) {
21 credential_fill(&c);
22 if (c.username)
23 printf("username=%s\n", c.username);
24 if (c.password)
25 printf("password=%s\n", c.password);
26 } else if (!strcmp(op, "approve")) {
27 credential_approve(&c);
28 } else if (!strcmp(op, "reject")) {
29 credential_reject(&c);
30 } else {
31 usage(usage_msg);
32 }
33 return 0;
34 }