2222
2323__aptly_mirror_list()
2424{
25- aptly mirror list -raw
25+ aptly ${aptly_global_opts[@]} mirror list -raw
2626}
2727
2828__aptly_repo_list()
2929{
30- aptly repo list -raw
30+ aptly ${aptly_global_opts[@]} repo list -raw
3131}
3232
3333__aptly_snapshot_list()
3434{
35- aptly snapshot list -raw
35+ aptly ${aptly_global_opts[@]} snapshot list -raw
3636}
3737
3838__aptly_published_distributions()
3939{
40- aptly publish list -raw | cut -d ' ' -f 2 | sort | uniq
40+ aptly ${aptly_global_opts[@]} publish list -raw | cut -d ' ' -f 2 | sort | uniq
4141}
4242
4343__aptly_published_prefixes()
4444{
45- aptly publish list -raw | cut -d ' ' -f 1 | sort | uniq
45+ aptly ${aptly_global_opts[@]} publish list -raw | cut -d ' ' -f 1 | sort | uniq
4646}
4747
4848__aptly_prefixes_for_distribution()
4949{
50- aptly publish list -raw | awk -v dist="$1" '{ if (dist == $2) print $1 }' | sort | uniq
50+ aptly ${aptly_global_opts[@]} publish list -raw | awk -v dist="$1" '{ if (dist == $2) print $1 }' | sort | uniq
5151}
5252
53+
54+
5355_aptly()
5456{
5557 cur="${COMP_WORDS[COMP_CWORD]}"
5658 prev="${COMP_WORDS[COMP_CWORD-1]}"
5759 prevprev="${COMP_WORDS[COMP_CWORD-2]}"
5860
5961 commands="api config db graph mirror package publish repo serve snapshot task version"
60- options="-architectures= -config= -db-open-attempts= -dep-follow-all-variants -dep-follow-recommends -dep-follow-source -dep-follow-suggests -dep-verbose-resolve -gpg-provider="
62+
63+ options="-architectures -config -db-open-attempts -dep-follow-all-variants -dep-follow-recommends -dep-follow-source -dep-follow-suggests -dep-verbose-resolve -gpg-provider"
64+ options_without_arg="-dep-follow-all-variants -dep-follow-recommends -dep-follow-source -dep-follow-suggests -dep-verbose-resolve"
65+ options_with_arg="-architectures -db-open-attempts -gpg-provider"
66+ options_with_path_arg="-config"
67+
6168 db_subcommands="cleanup recover"
6269 mirror_subcommands="create drop edit show list rename search update"
6370 publish_subcommands="drop list repo snapshot switch update source"
@@ -69,12 +76,41 @@ _aptly()
6976 config_subcommands="show"
7077 api_subcommands="serve"
7178
72- local cmd subcmd numargs numoptions i
79+ local cmd subcmd numargs numoptions i aptly_global_opts
7380
7481 numargs=0
7582 numoptions=0
7683
84+ for opt in "${options_with_path_arg[@]}"; do
85+ [[ "$prev" == "$opt" ]] || continue
86+ compopt -o filenames 2>/dev/null
87+ _filedir
88+ return 0
89+ done
90+
7791 for (( i=1; i < $COMP_CWORD; i++ )); do
92+ word=${COMP_WORDS[i]}
93+ if [[ "$word" == -*=* ]]; then
94+ for o in "${options[@]}"; do
95+ [[ ${word%%=*} == "$o" ]] && aptly_global_opts+=("$word")
96+ done
97+ else
98+ for o in "${options_with_arg[@]}" ""${options_with_path_arg[@]}"" ; do
99+ if [[ "$word" == "$o" ]]; then
100+ if (( i + 1 < COMP_CWORD )); then
101+ aptly_global_opts+=("$word" "${COMP_WORDS[i+1]}")
102+ else
103+ aptly_global_opts+=("$word")
104+ fi
105+ (( i++ ))
106+ continue 2
107+ fi
108+ done
109+ fi
110+ for o in ${options_without_arg[@]}; do
111+ [[ "$word" == "$o" ]] && aptly_global_opts+=("$word")
112+ done
113+
78114 if [[ -n "$cmd" ]]; then
79115 if [[ ! -n "$subcmd" ]]; then
80116 subcmd=${COMP_WORDS[i]}
@@ -339,7 +375,7 @@ _aptly()
339375 if [[ "$cur" == -* ]]; then
340376 COMPREPLY=($(compgen -W "-accept-unsigned -force-replace -ignore-signatures -keyring= -no-remove-files -repo= -uploaders-file=" -- ${cur}))
341377 else
342- comptopt -o filenames 2>/dev/null
378+ compopt -o filenames 2>/dev/null
343379 COMPREPLY=($(compgen -f -- ${cur}))
344380 return 0
345381 fi
0 commit comments