create_work: error out if bad ID arg in "--target_host ID" etc.

Actually we just check that the arg is nonzero.
We could look up the DB record (e.g. the host record)
but that would slow down mass job creation.
This commit is contained in:
David Anderson 2014-05-21 09:20:33 -07:00
parent a275fc7a0b
commit 03850d103d
1 changed files with 14 additions and 0 deletions

View File

@ -158,6 +158,15 @@ void JOB_DESC::parse_cmdline(int argc, char** argv) {
}
}
void check_assign_id(int x) {
if (x == 0) {
fprintf(stderr,
"you must specify a nonzero database ID for assigning jobs to users, teams, or hosts.\n"
);
exit(1);
}
}
int main(int argc, char** argv) {
DB_APP app;
int retval;
@ -235,23 +244,28 @@ int main(int argc, char** argv) {
jd.assign_type = ASSIGN_USER;
jd.assign_multi = true;
jd.assign_id = atoi(argv[++i]);
check_assign_id(jd.assign_id);
} else if (arg(argv, i, "broadcast_team")) {
jd.assign_flag = true;
jd.assign_type = ASSIGN_TEAM;
jd.assign_multi = true;
jd.assign_id = atoi(argv[++i]);
check_assign_id(jd.assign_id);
} else if (arg(argv, i, "target_host")) {
jd.assign_flag = true;
jd.assign_type = ASSIGN_HOST;
jd.assign_id = atoi(argv[++i]);
check_assign_id(jd.assign_id);
} else if (arg(argv, i, "target_user")) {
jd.assign_flag = true;
jd.assign_type = ASSIGN_USER;
jd.assign_id = atoi(argv[++i]);
check_assign_id(jd.assign_id);
} else if (arg(argv, i, "target_team")) {
jd.assign_flag = true;
jd.assign_type = ASSIGN_TEAM;
jd.assign_id = atoi(argv[++i]);
check_assign_id(jd.assign_id);
} else if (arg(argv, i, "help")) {
usage();
exit(0);