cli: accept numeric difficulty values
This commit is contained in:
parent
8ff5890abe
commit
b2b7645cab
1 changed files with 9 additions and 0 deletions
|
@ -165,6 +165,7 @@ int cli_args(int argc, char **argv, CLIAction *a) {
|
|||
break;
|
||||
case 'd':
|
||||
a->diff = D_Any;
|
||||
|
||||
for(int i = D_Easy ; i <= NUM_SELECTABLE_DIFFICULTIES; i++) {
|
||||
if(strcasecmp(optarg, difficulty_name(i)) == 0) {
|
||||
a->diff = i;
|
||||
|
@ -172,6 +173,14 @@ int cli_args(int argc, char **argv, CLIAction *a) {
|
|||
}
|
||||
}
|
||||
|
||||
if(a->diff == D_Any) {
|
||||
char *end;
|
||||
int dval = strtol(optarg, &end, 10);
|
||||
if(dval >= D_Easy && dval <= D_Lunatic && end == optarg + strlen(optarg)) {
|
||||
a->diff = dval;
|
||||
}
|
||||
}
|
||||
|
||||
if(a->diff == D_Any) {
|
||||
log_fatal("Invalid difficulty '%s'", optarg);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue