Skip to content

Commit

Permalink
Fix autocompletion (#5322)
Browse files Browse the repository at this point in the history
* remove command sorting from autocompletion. Fix #5321

* add comment. Fix #5319

* update crab-bash-completion.sh
  • Loading branch information
belforte authored Jul 14, 2024
1 parent 2a177d0 commit 05e977b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
8 changes: 4 additions & 4 deletions etc/crab-bash-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ _UseCrab ()
"")
case "$cur" in
"")
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) )
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) )
;;
-*)
COMPREPLY=( $(compgen -W '--version --help -h --quiet --debug' -- $cur) )
;;
*)
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) )
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) )
;;
esac
;;
Expand Down Expand Up @@ -355,10 +355,10 @@ _UseCrab ()
;;

*)
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) )
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) )
;;
esac

return 0
}
complete -F _UseCrab -o filenames -o nosort crab
complete -F _UseCrab -o filenames crab
26 changes: 8 additions & 18 deletions scripts/generate_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@

logging.basicConfig(level=logging.INFO)

######################################################
# Make sure that 'complete` command in template below meet following rules
# - Starts with: complete\s+-F\s+<crab-function-name>\s+
# - Ends with: \s+crab
# Otherwise suggest changes in crab-build.file in cms-sw/cmsdist repository
#####################################################

template = """
_UseCrab ()
{{
Expand Down Expand Up @@ -77,7 +84,7 @@
return 0
}}
complete -F _UseCrab -o filenames -o nosort crab
complete -F _UseCrab -o filenames crab
"""

template_cmd = """
Expand Down Expand Up @@ -155,23 +162,6 @@ def __init__(self):
cmdflags=' '.join(flags),
cmdoptions=' '.join(opts))


# sort the output of "crab <tab> <tab>"
# the higher the number the earlier a crab command is shown
weights = {
"status": 1000,
"tasks": 200,
"submit": 110,
"proceed": 100,
}
# current sorting as of 2024-05-14. Do we still want to keep this?
#checkwrite getlog checkusername checkdataset checkfile
#submit getoutput resubmit kill uploadlog
#remake report preparelocal createmyproxy setdatasetstatus setfilestatus

longnames_w = [(name, weights[name] if name in weights else 0) for name in longnames]
longnames_w = sorted(longnames_w, key=lambda x: x[1], reverse=True)
longnames = [l_w[0] for l_w in longnames_w]
logging.info(longnames)

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

0 comments on commit 05e977b

Please sign in to comment.