Skip to content

Commit

Permalink
Merge pull request #1670 from goblint/arg-complete-0.2.0
Browse files Browse the repository at this point in the history
Update bash-completion for arg-complete 0.2.x, remove `Arg_complete.Rest_all_compat`
  • Loading branch information
sim642 authored Feb 12, 2025
2 parents 01ae89b + b680436 commit 2178c51
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Goblint includes analyses for assertions, overflows, deadlocks, etc and can be e
(sha (>= 1.12))
(fileutils (>= 0.6.4))
cpu
arg-complete
(arg-complete (>= 0.2.1))
(yaml (>= 3.0.0))
uuidm
catapult
Expand Down
2 changes: 1 addition & 1 deletion goblint.opam
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ depends: [
"sha" {>= "1.12"}
"fileutils" {>= "0.6.4"}
"cpu"
"arg-complete"
"arg-complete" {>= "0.2.1"}
"yaml" {>= "3.0.0"}
"uuidm"
"catapult"
Expand Down
2 changes: 1 addition & 1 deletion goblint.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bug-reports: "https://github.com/goblint/analyzer/issues"
depends: [
"angstrom" {= "0.16.0"}
"apron" {= "v0.9.15"}
"arg-complete" {= "0.1.0"}
"arg-complete" {= "0.2.1"}
"astring" {= "0.8.5"}
"base-bigarray" {= "base"}
"base-bytes" {= "base"}
Expand Down
24 changes: 22 additions & 2 deletions scripts/bash-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,27 @@
# Permanent usage:
# Run: echo "source $(readlink -f .)/scripts/bash-completion.sh" >> ~/.bash_completion

# Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
# Copied & modified from standard __ltrim_colon_completions
__ltrim_equal_completions()
{
if [[ $1 == *=* && $COMP_WORDBREAKS == *=* ]]; then
# Remove equal-word prefix from COMPREPLY items
local equal_word=${1%"${1##*=}"}
local i=${#COMPREPLY[*]}
while ((i-- > 0)); do
COMPREPLY[i]=${COMPREPLY[i]#"$equal_word"}
done
fi
}

_goblint ()
{
IFS=$'\n'
COMPREPLY=($(${COMP_WORDS[0]} --complete "${COMP_WORDS[@]:1:COMP_CWORD}"))
local words cword cur
_get_comp_words_by_ref -n = cur words cword # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
COMPREPLY=($(${words[0]} --complete "${words[@]:1:cword}"))
__ltrim_equal_completions "$cur" # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
}

complete -o default -F _goblint goblint
Expand All @@ -26,7 +43,10 @@ _regtest ()
COMPREPLY=($(ls -1 tests/regression/${COMP_WORDS[1]}-* | sed -n -r 's/([0-9][0-9])-.*/\1/p' | grep "^${COMP_WORDS[2]}"))
;;
*)
COMPREPLY=($($(dirname ${COMP_WORDS[0]})/goblint --complete "${COMP_WORDS[@]:3:COMP_CWORD}"))
local words cword cur
_get_comp_words_by_ref -n = cur words cword # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
COMPREPLY=($($(dirname ${words[0]})/goblint --complete "${words[@]:3:cword}"))
__ltrim_equal_completions "$cur" # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
;;
esac
}
Expand Down
4 changes: 1 addition & 3 deletions src/maingoblint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ let rec option_spec_list: Arg_complete.speclist Lazy.t = lazy (
; "--html" , Arg_complete.Unit (fun _ -> configure_html ()),""
; "--sarif" , Arg_complete.Unit (fun _ -> configure_sarif ()),""
; "--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)], ""
; "--complete" , Arg_complete.Rest_all_compat.spec (Lazy.force rest_all_complete), ""
; "--complete" , Arg_complete.Rest_all (complete, Arg_complete.empty_all), ""
] @ defaults_spec_list (* lowest priority *)
)
and rest_all_complete = lazy (Arg_complete.Rest_all_compat.create complete Arg_complete.empty_all)
and complete args =
Arg_complete.complete_argv args (Lazy.force option_spec_list) Arg_complete.empty
|> List.iter print_endline; (* nosemgrep: print-not-logging *)
Expand Down Expand Up @@ -215,7 +214,6 @@ let parse_arguments () =
let anon_arg = set_string "files[+]" in
let arg_speclist = Arg_complete.arg_speclist (Lazy.force option_spec_list) in
Arg.parse arg_speclist anon_arg "Look up options using 'goblint --help'.";
Arg_complete.Rest_all_compat.finish (Lazy.force rest_all_complete);
begin match !writeconffile with
| Some writeconffile ->
GobConfig.write_file writeconffile;
Expand Down

0 comments on commit 2178c51

Please sign in to comment.