Skip to content

Commit

Permalink
Merge pull request #5745 from grondo/completions-update
Browse files Browse the repository at this point in the history
completions: support completion of jobids with plain `f`, support flux-hostlist(1)
  • Loading branch information
mergify[bot] committed Feb 20, 2024
2 parents 9497712 + 8d62313 commit 925bfc1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
3 changes: 3 additions & 0 deletions doc/man1/flux-jobs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ The field names that can be specified are:
**id.f58**
job ID in RFC 19 F58 (base58) encoding

**id.f58plain**
job ID in RFC 19 F58 encoding with ascii ``f``

**id.dec**
job ID in decimal representation

Expand Down
58 changes: 53 additions & 5 deletions etc/completions/flux.pre
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ __get_flux_subcommands() {
echo "$subcommands"
}

# Helper to emit id.f58plain when match begins with `f`
_flux_id_fmt()
{
local cur=$1
local fmt="{id}"
if [[ $cur == f* ]]; then
fmt="{id.f58plain}"
fi
echo "${fmt}"
}

# flux-cancel(1) completions
_flux_cancel()
{
Expand All @@ -143,7 +154,7 @@ _flux_cancel()
"
if [[ $cur != -* ]]; then
# Attempt to substitute an active jobid
active_jobs=$(flux jobs -no {id})
active_jobs=$(flux jobs -no $(_flux_id_fmt $cur))
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
return 0
fi
Expand All @@ -165,7 +176,7 @@ _flux_update()
"
if [[ $cur != -* ]]; then
# Attempt to substitute an active jobid
active_jobs="$(flux jobs -no {id})"
active_jobs="$(flux jobs -no $(_flux_id_fmt $cur))"
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
return 0
fi
Expand All @@ -177,6 +188,40 @@ _flux_update()
return 0
}

# flux-hostlist(1) completions
_flux_hostlist()
{
local cmd=$1
OPTS="\
-e --expand \
-d --delimiter= \
-c --count \
-n --nth \
-L --limit= \
-S --sort \
-x --exclude= \
-u --union --unique \
-i --intersect \
-m --minus \
-X --xor \
-f --fallback \
-q --quiet \
"
if [[ $cur != -* ]]; then
# Substitute source name or recent jobid
jobs="$(flux jobs -ano $(_flux_id_fmt $cur))"
sources="local instance avail stdin $jobs"
COMPREPLY=( $(compgen -W "$sources $jobs" -- "$cur") )
return 0
fi
COMPREPLY=( $(compgen -W "${OPTS} -h --help" -- "$cur") )
if [[ "${COMPREPLY[@]}" == *= ]]; then
# Add space if there is not a '=' in suggestions
compopt -o nospace
fi
return 0
}

# flux-{run,submit,batch,alloc,bulksubmit}(1) completions
_flux_submit_commands()
{
Expand Down Expand Up @@ -516,7 +561,7 @@ _flux_job()
if [[ $cur != -* ]]; then
if _flux_contains_word ${cmd} ${subcmds}; then
# These commands take active jobids by default:
active_jobs=$(flux jobs -no {id})
active_jobs=$(flux jobs -no $(_flux_id_fmt $cur))
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
return 0
fi
Expand Down Expand Up @@ -1080,7 +1125,7 @@ _flux_watch()
"
if [[ $cur != -* ]]; then
# Attempt to substitute an active jobid
active_jobs=$(flux jobs -no {id})
active_jobs=$(flux jobs -no $(_flux_id_fmt $cur))
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
return 0
fi
Expand Down Expand Up @@ -1141,7 +1186,7 @@ _flux_top()
return 0
fi
# flux-top(1) can target jobids that are also instances
local jobs=$(flux jobs -no {uri}:{id} | grep -v ^None: \
local jobs=$(flux jobs -no {uri}:$(_flux_id_fmt $cur) | grep -v ^None: \
| sed -n 's/.*://p')
COMPREPLY=( $(compgen -W "${OPTS} $jobs" -- "$cur") )
if [[ "${COMPREPLY[@]}" == *= ]]; then
Expand Down Expand Up @@ -1499,6 +1544,9 @@ _flux_core()
update)
_flux_update $subcmd
;;
hostlist)
_flux_hostlist $subcmd
;;
-*)
COMPREPLY=( $(compgen -W "${FLUX_OPTS}" -- "$cur") )
;;
Expand Down
2 changes: 2 additions & 0 deletions src/bindings/python/flux/job/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ def job_fields_to_attrs(fields):
"id.dec": (),
"id.hex": (),
"id.f58": (),
"id.f58plain": (),
"id.emoji": (),
"id.kvs": (),
"id.words": (),
Expand Down Expand Up @@ -736,6 +737,7 @@ class JobInfoFormat(flux.util.OutputFormat):
"id.dec": "JOBID",
"id.hex": "JOBID",
"id.f58": "JOBID",
"id.f58plain": "JOBID",
"id.emoji": "JOBID",
"id.kvs": "JOBID",
"id.words": "JOBID",
Expand Down
8 changes: 5 additions & 3 deletions t/t2800-jobs-cmd.t
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,14 @@ test_expect_success 'flux-jobs --format={id} works' '
test_cmp idsI.out inactive.ids
'

test_expect_success 'flux-jobs --format={id.f58},{id.hex},{id.dothex},{id.words} works' '
flux jobs -ano {id.dec},{id.f58},{id.hex},{id.kvs},{id.dothex},{id.words} \
test_expect_success 'flux-jobs --format={id.f58},{id.f58plain},{id.hex},{id.dothex},{id.words} works' '
flux jobs -ano {id.dec},{id.f58},{id.f58plain},{id.hex},{id.kvs},{id.dothex},{id.words} \
| sort -n > ids.XX.out &&
for id in $(cat all.ids); do
printf "%s,%s,%s,%s,%s,%s\n" \
printf "%s,%s,%s,%s,%s,%s,%s\n" \
$(flux job id --to=dec $id) \
$(flux job id --to=f58 $id) \
$(flux job id --to=f58plain $id) \
$(flux job id --to=hex $id) \
$(flux job id --to=kvs $id) \
$(flux job id --to=dothex $id) \
Expand Down Expand Up @@ -1157,6 +1158,7 @@ test_expect_success 'flux-jobs: header included with all custom formats' '
cat <<-EOF >headers.expected &&
id==JOBID
id.f58==JOBID
id.f58plain==JOBID
id.hex==JOBID
id.dothex==JOBID
id.words==JOBID
Expand Down

0 comments on commit 925bfc1

Please sign in to comment.