Skip to content

Commit 4cf6d22

Browse files
committed
refactor(tar): move variable declarations to the relevant places
1 parent c298dcf commit 4cf6d22

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

completions/tar

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ _comp_cmd_gtar__parse_help_line()
119119
done <<<"$1"
120120
}
121121

122+
# Parse the output of "tar --help" with GNU tar and store the parse results
123+
# into variables.
124+
#
125+
# @var[out] long_opts
126+
# @var[out] short_opts
127+
# @var[out] long_arg_none
128+
# @var[out] long_arg_opt
129+
# @var[out] long_arg_req
130+
# @var[out] short_arg_none
131+
# @var[out] short_arg_opt
132+
# @var[out] short_arg_req
133+
# The parse results are returned in these variables.
122134
_comp_cmd_gtar__parse_help()
123135
{
124136
local str line arg
@@ -193,6 +205,10 @@ _comp_cmd_tar__parse_old_opt()
193205
}
194206

195207
# Make the analysis of whole command line.
208+
#
209+
# @var[out] old_opt_progress
210+
# @var[out] old_opt_used
211+
# @var[out,array] old_opt_parsed
196212
_comp_cmd_tar__preparse_cmdline()
197213
{
198214
local first_arg=set i modes="ctxurdA"
@@ -507,11 +523,8 @@ _comp_cmd_tar__detect_ext()
507523

508524
_comp_cmd_tar__gnu()
509525
{
510-
local long_opts short_opts basic_tar="" \
511-
long_arg_none="" long_arg_opt="" long_arg_req="" \
512-
short_arg_none="" short_arg_opt="" short_arg_req="" \
513-
tar_mode tar_mode_arg old_opt_progress="" \
514-
old_opt_used="" old_opt_parsed=()
526+
local basic_tar="" \
527+
tar_mode tar_mode_arg
515528

516529
# Main mode, e.g. "x" or "c" or the long forms "extract" or "create"
517530
local tar_mode=none
@@ -528,12 +541,15 @@ _comp_cmd_tar__gnu()
528541
fi
529542

530543
local cur prev words cword was_split comp_args
531-
532544
_comp_initialize -s -- "$@" || return
533545

534546
# Fill the {long,short}_{opts,arg*}
547+
local long_opts short_opts \
548+
long_arg_none="" long_arg_opt="" long_arg_req="" \
549+
short_arg_none="" short_arg_opt="" short_arg_req=""
535550
_comp_cmd_gtar__parse_help
536551

552+
local old_opt_progress="" old_opt_used="" old_opt_parsed=()
537553
_comp_cmd_tar__preparse_cmdline "${words[@]}"
538554

539555
local ext
@@ -694,11 +710,8 @@ _comp_cmd_tar__posix_prev_handle()
694710

695711
_comp_cmd_tar__posix()
696712
{
697-
local long_opts short_opts basic_tar=set \
698-
long_arg_none="" long_arg_opt long_arg_req="" \
699-
short_arg_none short_arg_opt short_arg_req \
700-
tar_mode tar_mode_arg old_opt_progress="" \
701-
old_opt_used=set old_opt_parsed=()
713+
local basic_tar=set \
714+
tar_mode tar_mode_arg
702715

703716
# Main mode, e.g. -x or -c (extract/creation)
704717
local tar_mode=none
@@ -710,15 +723,20 @@ _comp_cmd_tar__posix()
710723
local tar_compression_mode=none
711724

712725
local cur prev words cword was_split comp_args
713-
714726
_comp_initialize -s -- "$@" || return
715727

728+
# Initialize option variables:
716729
# relatively compatible modes are {c,t,x}
717730
# relatively compatible options {b,f,m,v,w}
731+
# Note: long_opts, long_arg_*, short_arg_opt are currently unused
732+
local long_opts short_opts \
733+
long_arg_none="" long_arg_opt long_arg_req="" \
734+
short_arg_none short_arg_opt short_arg_req
718735
short_arg_req="fb"
719736
short_arg_none="wmv"
720737
short_opts="$short_arg_req$short_arg_none"
721738

739+
local old_opt_progress="" old_opt_used=set old_opt_parsed=()
722740
_comp_cmd_tar__preparse_cmdline "${words[@]}"
723741

724742
local ext

0 commit comments

Comments
 (0)