Skip to content

Commit 2178c51

Browse files
authored
Merge pull request #1670 from goblint/arg-complete-0.2.0
Update bash-completion for arg-complete 0.2.x, remove `Arg_complete.Rest_all_compat`
2 parents 01ae89b + b680436 commit 2178c51

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Goblint includes analyses for assertions, overflows, deadlocks, etc and can be e
5858
(sha (>= 1.12))
5959
(fileutils (>= 0.6.4))
6060
cpu
61-
arg-complete
61+
(arg-complete (>= 0.2.1))
6262
(yaml (>= 3.0.0))
6363
uuidm
6464
catapult

goblint.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ depends: [
5858
"sha" {>= "1.12"}
5959
"fileutils" {>= "0.6.4"}
6060
"cpu"
61-
"arg-complete"
61+
"arg-complete" {>= "0.2.1"}
6262
"yaml" {>= "3.0.0"}
6363
"uuidm"
6464
"catapult"

goblint.opam.locked

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bug-reports: "https://github.com/goblint/analyzer/issues"
2424
depends: [
2525
"angstrom" {= "0.16.0"}
2626
"apron" {= "v0.9.15"}
27-
"arg-complete" {= "0.1.0"}
27+
"arg-complete" {= "0.2.1"}
2828
"astring" {= "0.8.5"}
2929
"base-bigarray" {= "base"}
3030
"base-bytes" {= "base"}

scripts/bash-completion.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,27 @@
66
# Permanent usage:
77
# Run: echo "source $(readlink -f .)/scripts/bash-completion.sh" >> ~/.bash_completion
88

9+
# Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
10+
# Copied & modified from standard __ltrim_colon_completions
11+
__ltrim_equal_completions()
12+
{
13+
if [[ $1 == *=* && $COMP_WORDBREAKS == *=* ]]; then
14+
# Remove equal-word prefix from COMPREPLY items
15+
local equal_word=${1%"${1##*=}"}
16+
local i=${#COMPREPLY[*]}
17+
while ((i-- > 0)); do
18+
COMPREPLY[i]=${COMPREPLY[i]#"$equal_word"}
19+
done
20+
fi
21+
}
22+
923
_goblint ()
1024
{
1125
IFS=$'\n'
12-
COMPREPLY=($(${COMP_WORDS[0]} --complete "${COMP_WORDS[@]:1:COMP_CWORD}"))
26+
local words cword cur
27+
_get_comp_words_by_ref -n = cur words cword # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
28+
COMPREPLY=($(${words[0]} --complete "${words[@]:1:cword}"))
29+
__ltrim_equal_completions "$cur" # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
1330
}
1431

1532
complete -o default -F _goblint goblint
@@ -26,7 +43,10 @@ _regtest ()
2643
COMPREPLY=($(ls -1 tests/regression/${COMP_WORDS[1]}-* | sed -n -r 's/([0-9][0-9])-.*/\1/p' | grep "^${COMP_WORDS[2]}"))
2744
;;
2845
*)
29-
COMPREPLY=($($(dirname ${COMP_WORDS[0]})/goblint --complete "${COMP_WORDS[@]:3:COMP_CWORD}"))
46+
local words cword cur
47+
_get_comp_words_by_ref -n = cur words cword # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
48+
COMPREPLY=($($(dirname ${words[0]})/goblint --complete "${words[@]:3:cword}"))
49+
__ltrim_equal_completions "$cur" # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
3050
;;
3151
esac
3252
}

src/maingoblint.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ let rec option_spec_list: Arg_complete.speclist Lazy.t = lazy (
120120
; "--html" , Arg_complete.Unit (fun _ -> configure_html ()),""
121121
; "--sarif" , Arg_complete.Unit (fun _ -> configure_sarif ()),""
122122
; "--compare_runs" , Arg_complete.Tuple [Arg_complete.Set_string (tmp_arg, Arg_complete.empty); Arg_complete.String ((fun x -> set_auto "compare_runs" (sprintf "['%s','%s']" !tmp_arg x)), Arg_complete.empty)], ""
123-
; "--complete" , Arg_complete.Rest_all_compat.spec (Lazy.force rest_all_complete), ""
123+
; "--complete" , Arg_complete.Rest_all (complete, Arg_complete.empty_all), ""
124124
] @ defaults_spec_list (* lowest priority *)
125125
)
126-
and rest_all_complete = lazy (Arg_complete.Rest_all_compat.create complete Arg_complete.empty_all)
127126
and complete args =
128127
Arg_complete.complete_argv args (Lazy.force option_spec_list) Arg_complete.empty
129128
|> List.iter print_endline; (* nosemgrep: print-not-logging *)
@@ -215,7 +214,6 @@ let parse_arguments () =
215214
let anon_arg = set_string "files[+]" in
216215
let arg_speclist = Arg_complete.arg_speclist (Lazy.force option_spec_list) in
217216
Arg.parse arg_speclist anon_arg "Look up options using 'goblint --help'.";
218-
Arg_complete.Rest_all_compat.finish (Lazy.force rest_all_complete);
219217
begin match !writeconffile with
220218
| Some writeconffile ->
221219
GobConfig.write_file writeconffile;

0 commit comments

Comments
 (0)