From 05e977bb2acea5a465df9ea06f22d8e2fd8cbd26 Mon Sep 17 00:00:00 2001 From: Stefano Belforte Date: Sun, 14 Jul 2024 17:49:42 +0200 Subject: [PATCH] Fix autocompletion (#5322) * remove command sorting from autocompletion. Fix #5321 * add comment. Fix #5319 * update crab-bash-completion.sh --- etc/crab-bash-completion.sh | 8 ++++---- scripts/generate_completion.py | 26 ++++++++------------------ 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/etc/crab-bash-completion.sh b/etc/crab-bash-completion.sh index 561b3f34..952574b4 100644 --- a/etc/crab-bash-completion.sh +++ b/etc/crab-bash-completion.sh @@ -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 ;; @@ -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 diff --git a/scripts/generate_completion.py b/scripts/generate_completion.py index 2c0ecb45..a445edc1 100644 --- a/scripts/generate_completion.py +++ b/scripts/generate_completion.py @@ -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+\s+ +# - Ends with: \s+crab +# Otherwise suggest changes in crab-build.file in cms-sw/cmsdist repository +##################################################### + template = """ _UseCrab () {{ @@ -77,7 +84,7 @@ return 0 }} -complete -F _UseCrab -o filenames -o nosort crab +complete -F _UseCrab -o filenames crab """ template_cmd = """ @@ -155,23 +162,6 @@ def __init__(self): cmdflags=' '.join(flags), cmdoptions=' '.join(opts)) - - # sort the output of "crab " - # 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_: