| 1 |
#include "_helper.h" |
| 2 |
#include "account/account.h" |
| 3 |
#include "promptAndSet.h" |
| 4 |
#include "utils/string/stringUtils.h" |
| 5 |
|
| 6 |
void askOrNeedUsername(struct oidc_account* account, |
| 7 |
const struct arguments* arguments, int optional) { |
| 8 |
if (readUsername(account, arguments)) { |
| 9 |
return; |
| 10 |
} |
| 11 |
ERROR_IF_NO_PROMPT(optional, ERROR_MESSAGE("username", OPT_LONG_USERNAME)); |
| 12 |
char* res = |
| 13 |
_gen_prompt("Username", account_getUsername(account), 0, optional); |
| 14 |
if (res) { |
| 15 |
account_setUsername(account, res); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
int readUsername(struct oidc_account* account, |
| 20 |
const struct arguments* arguments) { |
| 21 |
if (arguments->op_username) { |
| 22 |
account_setUsername(account, oidc_strcopy(arguments->op_username)); |
| 23 |
return 1; |
| 24 |
} |
| 25 |
if (prompt_mode() == 0 && strValid(account_getUsername(account))) { |
| 26 |
return 1; |
| 27 |
} |
| 28 |
return 0; |
| 29 |
} |
| 30 |
|
| 31 |
void askUsername(struct oidc_account* account, |
| 32 |
const struct arguments* arguments) { |
| 33 |
return askOrNeedUsername(account, arguments, 1); |
| 34 |
} |
| 35 |
|
| 36 |
void needUsername(struct oidc_account* account, |
| 37 |
const struct arguments* arguments) { |
| 38 |
return askOrNeedUsername(account, arguments, 0); |
| 39 |
} |