Skip to content

Commit 05e977b

Browse files
authored
Fix autocompletion (#5322)
* remove command sorting from autocompletion. Fix #5321 * add comment. Fix #5319 * update crab-bash-completion.sh
1 parent 2a177d0 commit 05e977b

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

etc/crab-bash-completion.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ _UseCrab ()
2323
"")
2424
case "$cur" in
2525
"")
26-
COMPREPLY=( $(compgen -W '--version --help -h --quiet --debug status tasks submit proceed checkdataset checkfile checkusername checkwrite createmyproxy getlog getoutput getsandbox kill preparelocal recover remake report resubmit setdatasetstatus setfilestatus uploadlog' -- $cur) )
26+
COMPREPLY=( $(compgen -W '--version --help -h --quiet --debug checkdataset checkfile checkusername checkwrite createmyproxy getlog getoutput getsandbox kill preparelocal proceed recover remake report resubmit setdatasetstatus setfilestatus status submit tasks uploadlog' -- $cur) )
2727
;;
2828
-*)
2929
COMPREPLY=( $(compgen -W '--version --help -h --quiet --debug' -- $cur) )
3030
;;
3131
*)
32-
COMPREPLY=( $(compgen -W 'status tasks submit proceed checkdataset checkfile checkusername checkwrite createmyproxy getlog getoutput getsandbox kill preparelocal recover remake report resubmit setdatasetstatus setfilestatus uploadlog' -- $cur) )
32+
COMPREPLY=( $(compgen -W 'checkdataset checkfile checkusername checkwrite createmyproxy getlog getoutput getsandbox kill preparelocal proceed recover remake report resubmit setdatasetstatus setfilestatus status submit tasks uploadlog' -- $cur) )
3333
;;
3434
esac
3535
;;
@@ -355,10 +355,10 @@ _UseCrab ()
355355
;;
356356

357357
*)
358-
COMPREPLY=( $(compgen -W 'status tasks submit proceed checkdataset checkfile checkusername checkwrite createmyproxy getlog getoutput getsandbox kill preparelocal recover remake report resubmit setdatasetstatus setfilestatus uploadlog' -- $cur) )
358+
COMPREPLY=( $(compgen -W 'checkdataset checkfile checkusername checkwrite createmyproxy getlog getoutput getsandbox kill preparelocal proceed recover remake report resubmit setdatasetstatus setfilestatus status submit tasks uploadlog' -- $cur) )
359359
;;
360360
esac
361361

362362
return 0
363363
}
364-
complete -F _UseCrab -o filenames -o nosort crab
364+
complete -F _UseCrab -o filenames crab

scripts/generate_completion.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434

3535
logging.basicConfig(level=logging.INFO)
3636

37+
######################################################
38+
# Make sure that 'complete` command in template below meet following rules
39+
# - Starts with: complete\s+-F\s+<crab-function-name>\s+
40+
# - Ends with: \s+crab
41+
# Otherwise suggest changes in crab-build.file in cms-sw/cmsdist repository
42+
#####################################################
43+
3744
template = """
3845
_UseCrab ()
3946
{{
@@ -77,7 +84,7 @@
7784
7885
return 0
7986
}}
80-
complete -F _UseCrab -o filenames -o nosort crab
87+
complete -F _UseCrab -o filenames crab
8188
"""
8289

8390
template_cmd = """
@@ -155,23 +162,6 @@ def __init__(self):
155162
cmdflags=' '.join(flags),
156163
cmdoptions=' '.join(opts))
157164

158-
159-
# sort the output of "crab <tab> <tab>"
160-
# the higher the number the earlier a crab command is shown
161-
weights = {
162-
"status": 1000,
163-
"tasks": 200,
164-
"submit": 110,
165-
"proceed": 100,
166-
}
167-
# current sorting as of 2024-05-14. Do we still want to keep this?
168-
#checkwrite getlog checkusername checkdataset checkfile
169-
#submit getoutput resubmit kill uploadlog
170-
#remake report preparelocal createmyproxy setdatasetstatus setfilestatus
171-
172-
longnames_w = [(name, weights[name] if name in weights else 0) for name in longnames]
173-
longnames_w = sorted(longnames_w, key=lambda x: x[1], reverse=True)
174-
longnames = [l_w[0] for l_w in longnames_w]
175165
logging.info(longnames)
176166

177167
with open(p_args.output_file, "w", encoding="utf-8") as f_:

0 commit comments

Comments
 (0)