Skip to content

Commit 925bfc1

Browse files
authored
Merge pull request #5745 from grondo/completions-update
completions: support completion of jobids with plain `f`, support flux-hostlist(1)
2 parents 9497712 + 8d62313 commit 925bfc1

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed

doc/man1/flux-jobs.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ The field names that can be specified are:
287287
**id.f58**
288288
job ID in RFC 19 F58 (base58) encoding
289289

290+
**id.f58plain**
291+
job ID in RFC 19 F58 encoding with ascii ``f``
292+
290293
**id.dec**
291294
job ID in decimal representation
292295

etc/completions/flux.pre

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ __get_flux_subcommands() {
129129
echo "$subcommands"
130130
}
131131

132+
# Helper to emit id.f58plain when match begins with `f`
133+
_flux_id_fmt()
134+
{
135+
local cur=$1
136+
local fmt="{id}"
137+
if [[ $cur == f* ]]; then
138+
fmt="{id.f58plain}"
139+
fi
140+
echo "${fmt}"
141+
}
142+
132143
# flux-cancel(1) completions
133144
_flux_cancel()
134145
{
@@ -143,7 +154,7 @@ _flux_cancel()
143154
"
144155
if [[ $cur != -* ]]; then
145156
# Attempt to substitute an active jobid
146-
active_jobs=$(flux jobs -no {id})
157+
active_jobs=$(flux jobs -no $(_flux_id_fmt $cur))
147158
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
148159
return 0
149160
fi
@@ -165,7 +176,7 @@ _flux_update()
165176
"
166177
if [[ $cur != -* ]]; then
167178
# Attempt to substitute an active jobid
168-
active_jobs="$(flux jobs -no {id})"
179+
active_jobs="$(flux jobs -no $(_flux_id_fmt $cur))"
169180
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
170181
return 0
171182
fi
@@ -177,6 +188,40 @@ _flux_update()
177188
return 0
178189
}
179190

191+
# flux-hostlist(1) completions
192+
_flux_hostlist()
193+
{
194+
local cmd=$1
195+
OPTS="\
196+
-e --expand \
197+
-d --delimiter= \
198+
-c --count \
199+
-n --nth \
200+
-L --limit= \
201+
-S --sort \
202+
-x --exclude= \
203+
-u --union --unique \
204+
-i --intersect \
205+
-m --minus \
206+
-X --xor \
207+
-f --fallback \
208+
-q --quiet \
209+
"
210+
if [[ $cur != -* ]]; then
211+
# Substitute source name or recent jobid
212+
jobs="$(flux jobs -ano $(_flux_id_fmt $cur))"
213+
sources="local instance avail stdin $jobs"
214+
COMPREPLY=( $(compgen -W "$sources $jobs" -- "$cur") )
215+
return 0
216+
fi
217+
COMPREPLY=( $(compgen -W "${OPTS} -h --help" -- "$cur") )
218+
if [[ "${COMPREPLY[@]}" == *= ]]; then
219+
# Add space if there is not a '=' in suggestions
220+
compopt -o nospace
221+
fi
222+
return 0
223+
}
224+
180225
# flux-{run,submit,batch,alloc,bulksubmit}(1) completions
181226
_flux_submit_commands()
182227
{
@@ -516,7 +561,7 @@ _flux_job()
516561
if [[ $cur != -* ]]; then
517562
if _flux_contains_word ${cmd} ${subcmds}; then
518563
# These commands take active jobids by default:
519-
active_jobs=$(flux jobs -no {id})
564+
active_jobs=$(flux jobs -no $(_flux_id_fmt $cur))
520565
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
521566
return 0
522567
fi
@@ -1080,7 +1125,7 @@ _flux_watch()
10801125
"
10811126
if [[ $cur != -* ]]; then
10821127
# Attempt to substitute an active jobid
1083-
active_jobs=$(flux jobs -no {id})
1128+
active_jobs=$(flux jobs -no $(_flux_id_fmt $cur))
10841129
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
10851130
return 0
10861131
fi
@@ -1141,7 +1186,7 @@ _flux_top()
11411186
return 0
11421187
fi
11431188
# flux-top(1) can target jobids that are also instances
1144-
local jobs=$(flux jobs -no {uri}:{id} | grep -v ^None: \
1189+
local jobs=$(flux jobs -no {uri}:$(_flux_id_fmt $cur) | grep -v ^None: \
11451190
| sed -n 's/.*://p')
11461191
COMPREPLY=( $(compgen -W "${OPTS} $jobs" -- "$cur") )
11471192
if [[ "${COMPREPLY[@]}" == *= ]]; then
@@ -1499,6 +1544,9 @@ _flux_core()
14991544
update)
15001545
_flux_update $subcmd
15011546
;;
1547+
hostlist)
1548+
_flux_hostlist $subcmd
1549+
;;
15021550
-*)
15031551
COMPREPLY=( $(compgen -W "${FLUX_OPTS}" -- "$cur") )
15041552
;;

src/bindings/python/flux/job/info.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ def job_fields_to_attrs(fields):
641641
"id.dec": (),
642642
"id.hex": (),
643643
"id.f58": (),
644+
"id.f58plain": (),
644645
"id.emoji": (),
645646
"id.kvs": (),
646647
"id.words": (),
@@ -736,6 +737,7 @@ class JobInfoFormat(flux.util.OutputFormat):
736737
"id.dec": "JOBID",
737738
"id.hex": "JOBID",
738739
"id.f58": "JOBID",
740+
"id.f58plain": "JOBID",
739741
"id.emoji": "JOBID",
740742
"id.kvs": "JOBID",
741743
"id.words": "JOBID",

t/t2800-jobs-cmd.t

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,14 @@ test_expect_success 'flux-jobs --format={id} works' '
471471
test_cmp idsI.out inactive.ids
472472
'
473473

474-
test_expect_success 'flux-jobs --format={id.f58},{id.hex},{id.dothex},{id.words} works' '
475-
flux jobs -ano {id.dec},{id.f58},{id.hex},{id.kvs},{id.dothex},{id.words} \
474+
test_expect_success 'flux-jobs --format={id.f58},{id.f58plain},{id.hex},{id.dothex},{id.words} works' '
475+
flux jobs -ano {id.dec},{id.f58},{id.f58plain},{id.hex},{id.kvs},{id.dothex},{id.words} \
476476
| sort -n > ids.XX.out &&
477477
for id in $(cat all.ids); do
478-
printf "%s,%s,%s,%s,%s,%s\n" \
478+
printf "%s,%s,%s,%s,%s,%s,%s\n" \
479479
$(flux job id --to=dec $id) \
480480
$(flux job id --to=f58 $id) \
481+
$(flux job id --to=f58plain $id) \
481482
$(flux job id --to=hex $id) \
482483
$(flux job id --to=kvs $id) \
483484
$(flux job id --to=dothex $id) \
@@ -1157,6 +1158,7 @@ test_expect_success 'flux-jobs: header included with all custom formats' '
11571158
cat <<-EOF >headers.expected &&
11581159
id==JOBID
11591160
id.f58==JOBID
1161+
id.f58plain==JOBID
11601162
id.hex==JOBID
11611163
id.dothex==JOBID
11621164
id.words==JOBID

0 commit comments

Comments
 (0)