Skip to content

Commit

Permalink
flux-job: improve flux job info usage message
Browse files Browse the repository at this point in the history
Problem: the flux job info usage message is not output if the
job id is not specified, and is not reached if flux_open() fails.

In preparation for deprecating multi-key support, make the following
changes to the free argument parsing and usage message processing:
- check the arguments before flux_open()
- require exactly one key
- print the usage message even if the job id is not specified
- update usage message to reflect that only one key is accepted
- add key descriptions to the usage message

Update sharness test that checks usage message content.
  • Loading branch information
garlick committed Oct 27, 2023
1 parent 8036382 commit fa18b1e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
34 changes: 20 additions & 14 deletions src/cmd/flux-job.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ static struct optparse_subcommand subcommands[] = {
wait_event_opts
},
{ "info",
"id key ...",
"id key",
"Display info for a job",
cmd_info,
0,
Expand Down Expand Up @@ -3361,14 +3361,17 @@ int cmd_wait_event (optparse_t *p, int argc, char **argv)
void info_usage (void)
{
fprintf (stderr,
"Missing lookup key(s), common keys:\n"
"J\n"
"R\n"
"eventlog\n"
"jobspec\n"
"guest.exec.eventlog\n"
"guest.input\n"
"guest.output\n");
"Usage: flux job info id key\n"
"some useful keys are:\n"
" J - signed jobspec\n"
" R - allocated resources\n"
" eventlog - primary job eventlog\n"
" jobspec - job specification\n"
" guest.exec.eventlog - execution eventlog\n"
" guest.input - job input log\n"
" guest.output - job output log\n"
"Use flux job info -h to list available options\n");

}

struct info_ctx {
Expand Down Expand Up @@ -3562,6 +3565,9 @@ void info_lookup (flux_t *h,
flux_future_t *f;
struct info_ctx ctx = {0};

if (argc - optindex != 1)
log_msg_exit ("only one key may be looked up");

ctx.id_arg = argv[optindex-1];
ctx.id = id;
if (!(ctx.keys_input = json_array ()))
Expand Down Expand Up @@ -3642,13 +3648,13 @@ int cmd_info (optparse_t *p, int argc, char **argv)
int optindex = optparse_option_index (p);
flux_jobid_t id;

if (!(h = flux_open (NULL, 0)))
log_err_exit ("flux_open");

if ((argc - optindex) < 1) {
optparse_print_usage (p);
// Usage: flux job info id key
if (optindex - argc != 3) {
info_usage ();
exit (1);
}
if (!(h = flux_open (NULL, 0)))
log_err_exit ("flux_open");

id = parse_jobid (argv[optindex++]);

Expand Down
17 changes: 8 additions & 9 deletions t/t2230-job-info-lookup.t
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ test_expect_success 'flux job info fails without jobid' '
'

test_expect_success 'flux job info listing of keys works' '
jobid=$(submit_job) &&
flux job info $jobid > list_keys.err 2>&1 &&
grep "^J" list_keys.err &&
grep "^R" list_keys.err &&
grep "^eventlog" list_keys.err &&
grep "^jobspec" list_keys.err &&
grep "^guest.exec.eventlog" list_keys.err &&
grep "^guest.input" list_keys.err &&
grep "^guest.output" list_keys.err
test_must_fail flux job info 2>list_keys.err &&
grep J list_keys.err &&
grep R list_keys.err &&
grep eventlog list_keys.err &&
grep jobspec list_keys.err &&
grep guest.exec.eventlog list_keys.err &&
grep guest.input list_keys.err &&
grep guest.output list_keys.err
'

#
Expand Down

0 comments on commit fa18b1e

Please sign in to comment.