Debian Codegraph @

src/oidc-gen/promptAndSet/name.c

raw
1 #include "_helper.h"
2 #include "account/account.h"
3 #include "promptAndSet.h"
4 #include "utils/prompt.h"
5 #include "utils/string/stringUtils.h"
6
7 void askOrNeedName(struct oidc_account* account,
8 const struct arguments* arguments, int optional) {
9 if (readName(account, arguments)) {
10 return;
11 }
12 ERROR_IF_NO_PROMPT(optional, "No account short name given.");
13 char* shortname = NULL;
14 do {
15 secFree(shortname);
16 shortname = prompt("Enter short name for the account to configure",
17 "short name", NULL, CLI_PROMPT_VERBOSE);
18 } while (!strValid(shortname) || optional);
19 if (shortname) {
20 account_setName(account, shortname, arguments->cnid);
21 }
22 }
23
24 int readName(struct oidc_account* account, const struct arguments* arguments) {
25 if (arguments->args[0]) {
26 account_setName(account, oidc_strcopy(arguments->args[0]), arguments->cnid);
27 return 1;
28 }
29 if (prompt_mode() == 0 && strValid(account_getName(account))) {
30 return 1;
31 }
32 return 0;
33 }
34
35 void askName(struct oidc_account* account, const struct arguments* arguments) {
36 return askOrNeedName(account, arguments, 1);
37 }
38
39 void needName(struct oidc_account* account, const struct arguments* arguments) {
40 return askOrNeedName(account, arguments, 0);
41 }