autospec, plugins: rework the logic of the command-line options parser
Signed-off-by: Davide Madrisan <davide.madrisan@gmail.com>
This commit is contained in:
parent
eb0f465be0
commit
29e18765b6
@ -49,6 +49,15 @@ Changes in version 1.16.0
|
|||||||
Remove all the partial .po files and dinamically create a global .pot
|
Remove all the partial .po files and dinamically create a global .pot
|
||||||
file which will be merged to autospec.po at every build.
|
file which will be merged to autospec.po at every build.
|
||||||
|
|
||||||
|
+ update
|
||||||
|
* autospec - Davide Madrisan:
|
||||||
|
Remove the obsolete option '-r|--colorize'.
|
||||||
|
|
||||||
|
+ bugfix
|
||||||
|
* autospec, plugins/* - Davide Madrisan:
|
||||||
|
Rework the logic of the command-line options parser to let it work in
|
||||||
|
conjunction with the late load of the configuration files.
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
Changes in version 1.14.3
|
Changes in version 1.14.3
|
||||||
|
40
autospec.in
40
autospec.in
@ -94,7 +94,7 @@ notify.disable_colors
|
|||||||
exit 1; }
|
exit 1; }
|
||||||
|
|
||||||
. @libdir@/libcfg.lib
|
. @libdir@/libcfg.lib
|
||||||
|
|
||||||
# Little helper function for reading args from the commandline.
|
# Little helper function for reading args from the commandline.
|
||||||
# it automatically handles -a b and -a=b variants, and returns 1 if
|
# it automatically handles -a b and -a=b variants, and returns 1 if
|
||||||
# we need to shift $3.
|
# we need to shift $3.
|
||||||
@ -116,6 +116,8 @@ function read_arg() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args=()
|
args=()
|
||||||
|
cmdline_vars=()
|
||||||
|
|
||||||
while (($# > 0)); do
|
while (($# > 0)); do
|
||||||
args[${#args[*]}]="$1"
|
args[${#args[*]}]="$1"
|
||||||
case ${1%%=*} in
|
case ${1%%=*} in
|
||||||
@ -131,32 +133,39 @@ while (($# > 0)); do
|
|||||||
let "verbose = 2" ;;
|
let "verbose = 2" ;;
|
||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
let "verbose = 0" ;;
|
let "verbose = 0" ;;
|
||||||
-r|--colorize)
|
|
||||||
notify.warning $"\
|
|
||||||
deprecated option"" \`-r|--colorize': "$"use \`--colors' instead"
|
|
||||||
# for backward compatibility
|
|
||||||
selected_color_scheme="default" ;;
|
|
||||||
-h|--help)
|
-h|--help)
|
||||||
let "print_help = 1" ;;
|
let "print_help = 1" ;;
|
||||||
-V|--version)
|
-V|--version)
|
||||||
let "print_version = 1" ;;
|
let "print_version = 1" ;;
|
||||||
--colors)
|
--colors)
|
||||||
read_arg selected_color_scheme "$@" ||
|
read_arg color_scheme "$@" ||
|
||||||
{ shift; args[${#args[*]}]="$1"; } ;;
|
{ shift; args[${#args[*]}]="$1"; }
|
||||||
|
notify.debug "color_scheme = \"$color_scheme\""
|
||||||
|
cmdline_vars[${#cmdline_vars[*]}]="color_scheme=\"$color_scheme\""
|
||||||
|
;;
|
||||||
-C|--config)
|
-C|--config)
|
||||||
read_arg custom_cfgfile_list "$@" ||
|
read_arg cfgfile_list_cmdline "$@" ||
|
||||||
{ shift; args[${#args[*]}]="$1"; } ;;
|
{ shift; args[${#args[*]}]="$1"; }
|
||||||
*) ;;
|
notify.debug "cfgfile_list_cmdline = \"$cfgfile_list_cmdline\""
|
||||||
|
;;
|
||||||
|
*) ;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
notify.debug "[${me[0]}, "$"version"" ${me[1]}]"
|
notify.debug "[${me[0]}, "$"version"" ${me[1]}]"
|
||||||
|
|
||||||
[ "$selected_color_scheme" ] || color_scheme="$selected_color_scheme"
|
cfg_load_files "$cfgfile_list_cmdline"
|
||||||
|
|
||||||
notify.debug "custom_cfgfile_list = \"$custom_cfgfile_list\""
|
# otherwrite the configuration variables by set them again using
|
||||||
cfg_load_files "$custom_cfgfile_list"
|
# the values defined via the commanline options
|
||||||
|
for i in ${!cmdline_vars[@]}; do
|
||||||
|
notify.debug "eval \"${cmdline_vars[i]}\""
|
||||||
|
eval "${cmdline_vars[i]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
[ "$logging" = "1" ] && color_scheme="none"
|
||||||
|
notify.enable_colors "$color_scheme"
|
||||||
|
|
||||||
case "$(( $pck_update + $spec_create + $pck_extract + $config_getvar ))" in
|
case "$(( $pck_update + $spec_create + $pck_extract + $config_getvar ))" in
|
||||||
0) [ "$print_help" = "1" ] && autospec.usage 0
|
0) [ "$print_help" = "1" ] && autospec.usage 0
|
||||||
@ -172,9 +181,6 @@ case "$(( $pck_update + $spec_create + $pck_extract + $config_getvar ))" in
|
|||||||
*) autospec.usage 1 ;;
|
*) autospec.usage 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[ "$logging" = "1" ] && color_scheme="none"
|
|
||||||
notify.enable_colors "$color_scheme"
|
|
||||||
|
|
||||||
# checking for errors in the configuration file
|
# checking for errors in the configuration file
|
||||||
[ "$config_getvar" = 1 ] || config.integrity
|
[ "$config_getvar" = 1 ] || config.integrity
|
||||||
|
|
||||||
|
@ -116,7 +116,8 @@ function cfg_load_files() {
|
|||||||
notify.error $"configuration file not found"": $1"
|
notify.error $"configuration file not found"": $1"
|
||||||
# select a different list of user configuration files
|
# select a different list of user configuration files
|
||||||
cfgfile_list=(\
|
cfgfile_list=(\
|
||||||
`ls /etc/@package@.conf /etc/@package@.d/*.conf $1 2>/dev/null`)
|
`ls /etc/@package@.conf /etc/@package@.d/*.conf 2>/dev/null` \
|
||||||
|
`ls $1 2>/dev/null`)
|
||||||
else
|
else
|
||||||
# default configuration files
|
# default configuration files
|
||||||
cfgfile_list=(${default_cfg_list[@]})
|
cfgfile_list=(${default_cfg_list[@]})
|
||||||
|
@ -110,6 +110,8 @@ frontend_opts: \
|
|||||||
notify.debug "[ ${0} ${exec_options} ]\n"
|
notify.debug "[ ${0} ${exec_options} ]\n"
|
||||||
eval set -- "$exec_options"
|
eval set -- "$exec_options"
|
||||||
|
|
||||||
|
cmdline_vars=()
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-x|--extract) ;;
|
-x|--extract) ;;
|
||||||
@ -118,9 +120,16 @@ while :; do
|
|||||||
--destdir)
|
--destdir)
|
||||||
destdir="$2"; shift ;;
|
destdir="$2"; shift ;;
|
||||||
--colors)
|
--colors)
|
||||||
color_scheme="$2"; shift ;;
|
color_scheme="$2"; shift
|
||||||
|
notify.debug "color_scheme = \"$color_scheme\""
|
||||||
|
cmdline_vars[${#cmdline_vars[*]}]="color_scheme=\"$color_scheme\""
|
||||||
|
;;
|
||||||
-C|--config)
|
-C|--config)
|
||||||
custom_cfgfile_list="$2"; shift ;;
|
cfgfile_list_cmdline="$2"; shift
|
||||||
|
notify.debug "cfgfile_list_cmdline = \"$cfgfile_list_cmdline\""
|
||||||
|
cmdline_vars[${#cmdline_vars[*]}]="\
|
||||||
|
cfgfile_list_cmdline=\"$cfgfile_list_cmdline\""
|
||||||
|
;;
|
||||||
-D|--debug)
|
-D|--debug)
|
||||||
let "verbose = 2" ;;
|
let "verbose = 2" ;;
|
||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
@ -140,8 +149,14 @@ for arg in $@; do
|
|||||||
notify.error $"unrecognized option"" -- \`$arg'"
|
notify.error $"unrecognized option"" -- \`$arg'"
|
||||||
done
|
done
|
||||||
|
|
||||||
notify.debug "custom_cfgfile_list = \"$custom_cfgfile_list\""
|
cfg_load_files "$cfgfile_list_cmdline"
|
||||||
cfg_load_files "$custom_cfgfile_list"
|
|
||||||
|
# otherwrite the configuration variables by set them again using
|
||||||
|
# the values defined via the commanline options
|
||||||
|
for i in ${!cmdline_vars[@]}; do
|
||||||
|
notify.debug "eval \"${cmdline_vars[i]}\""
|
||||||
|
eval "${cmdline_vars[i]}"
|
||||||
|
done
|
||||||
|
|
||||||
notify.enable_colors "$color_scheme"
|
notify.enable_colors "$color_scheme"
|
||||||
|
|
||||||
|
@ -204,6 +204,8 @@ debug,quiet,help,version \
|
|||||||
|
|
||||||
eval set -- "$exec_options"
|
eval set -- "$exec_options"
|
||||||
|
|
||||||
|
cmdline_vars=()
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-u|--update) ;;
|
-u|--update) ;;
|
||||||
@ -237,7 +239,8 @@ while :; do
|
|||||||
ftp_server_upload_id="$2"
|
ftp_server_upload_id="$2"
|
||||||
shift ;;
|
shift ;;
|
||||||
--changelog)
|
--changelog)
|
||||||
changelog_commandline="$2"; shift ;;
|
changelog_cmdline="$2"; shift
|
||||||
|
notify.debug "changelog_cmdline = \"$changelog_cmdline\"" ;;
|
||||||
--nosrpm)
|
--nosrpm)
|
||||||
let "nosrpm = 1" ;;
|
let "nosrpm = 1" ;;
|
||||||
--norpm)
|
--norpm)
|
||||||
@ -278,9 +281,16 @@ while :; do
|
|||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
let "verbose = 0" ;;
|
let "verbose = 0" ;;
|
||||||
--colors)
|
--colors)
|
||||||
color_scheme="$2"; shift ;;
|
color_scheme="$2"; shift
|
||||||
|
notify.debug "color_scheme = \"$color_scheme\""
|
||||||
|
cmdline_vars[${#cmdline_vars[*]}]="color_scheme=\"$color_scheme\""
|
||||||
|
;;
|
||||||
-C|--config)
|
-C|--config)
|
||||||
custom_cfgfile_list="$2"; shift ;;
|
cfgfile_list_cmdline="$2"; shift
|
||||||
|
notify.debug "cfgfile_list_cmdline = \"$cfgfile_list_cmdline\""
|
||||||
|
cmdline_vars[${#cmdline_vars[*]}]="\
|
||||||
|
cfgfile_list_cmdline=\"$cfgfile_list_cmdline\""
|
||||||
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
usage 0 ;;
|
usage 0 ;;
|
||||||
-V|--version)
|
-V|--version)
|
||||||
@ -306,15 +316,19 @@ done
|
|||||||
notify.debug "${0} ${exec_options}"
|
notify.debug "${0} ${exec_options}"
|
||||||
#echo -e "[ ${0} \\ \n ${exec_options} ]\n"
|
#echo -e "[ ${0} \\ \n ${exec_options} ]\n"
|
||||||
|
|
||||||
notify.debug "changelog_commandline = \"$changelog_commandline\""
|
|
||||||
|
|
||||||
if [ -n "$rpm_rootdir" ]; then
|
if [ -n "$rpm_rootdir" ]; then
|
||||||
[ -d "$rpm_rootdir" ] ||
|
[ -d "$rpm_rootdir" ] ||
|
||||||
notify.error $"no such file or directory"": $rpm_rootdir"
|
notify.error $"no such file or directory"": $rpm_rootdir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
notify.debug "custom_cfgfile_list = \"$custom_cfgfile_list\""
|
cfg_load_files "$cfgfile_list_cmdline"
|
||||||
cfg_load_files "$custom_cfgfile_list"
|
|
||||||
|
# otherwrite the configuration variables by set them again using
|
||||||
|
# the values defined via the commanline options
|
||||||
|
for i in ${!cmdline_vars[@]}; do
|
||||||
|
notify.debug "eval \"${cmdline_vars[i]}\""
|
||||||
|
eval "${cmdline_vars[i]}"
|
||||||
|
done
|
||||||
|
|
||||||
[ "$logging" = "1" ] && color_scheme="none"
|
[ "$logging" = "1" ] && color_scheme="none"
|
||||||
notify.enable_colors "$color_scheme"
|
notify.enable_colors "$color_scheme"
|
||||||
@ -1211,8 +1225,8 @@ s|\(.*[ \t]*${define_list_name[$i]}[ \t]*\).*|\1${define_list_value[$i]}|}" \
|
|||||||
|
|
||||||
# set the changelog entry
|
# set the changelog entry
|
||||||
local changelog_new
|
local changelog_new
|
||||||
if [ "$changelog_commandline" ]; then
|
if [ "$changelog_cmdline" ]; then
|
||||||
changelog_new="$changelog_commandline"
|
changelog_new="$changelog_cmdline"
|
||||||
elif [ "$changelog_userdef" ]; then
|
elif [ "$changelog_userdef" ]; then
|
||||||
changelog_new="$changelog_userdef"
|
changelog_new="$changelog_userdef"
|
||||||
else
|
else
|
||||||
|
@ -172,6 +172,8 @@ frontend_opts: \
|
|||||||
notify.debug "[ ${0} ${exec_options} ]\n"
|
notify.debug "[ ${0} ${exec_options} ]\n"
|
||||||
eval set -- "$exec_options"
|
eval set -- "$exec_options"
|
||||||
|
|
||||||
|
cmdline_vars=()
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-s|--source)
|
-s|--source)
|
||||||
@ -198,9 +200,16 @@ while :; do
|
|||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
let "verbose = 0" ;;
|
let "verbose = 0" ;;
|
||||||
--colors)
|
--colors)
|
||||||
color_scheme="$2"; shift ;;
|
color_scheme="$2"; shift
|
||||||
|
notify.debug "color_scheme = \"$color_scheme\""
|
||||||
|
cmdline_vars[${#cmdline_vars[*]}]="color_scheme=\"$color_scheme\""
|
||||||
|
;;
|
||||||
-C|--config)
|
-C|--config)
|
||||||
custom_cfgfile_list="$2"; shift ;;
|
cfgfile_list_cmdline="$2"; shift
|
||||||
|
notify.debug "cfgfile_list_cmdline = \"$cfgfile_list_cmdline\""
|
||||||
|
cmdline_vars[${#cmdline_vars[*]}]="\
|
||||||
|
cfgfile_list_cmdline=\"$cfgfile_list_cmdline\""
|
||||||
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
usage 0 ;;
|
usage 0 ;;
|
||||||
-V|--version)
|
-V|--version)
|
||||||
@ -215,8 +224,14 @@ for arg in $@; do
|
|||||||
notify.error $"unrecognized option"" -- \`$arg'"
|
notify.error $"unrecognized option"" -- \`$arg'"
|
||||||
done
|
done
|
||||||
|
|
||||||
notify.debug "custom_cfgfile_list = \"$custom_cfgfile_list\""
|
cfg_load_files "$cfgfile_list_cmdline"
|
||||||
cfg_load_files "$custom_cfgfile_list"
|
|
||||||
|
# otherwrite the configuration variables by set them again using
|
||||||
|
# the values defined via the commanline options
|
||||||
|
for i in ${!cmdline_vars[@]}; do
|
||||||
|
notify.debug "eval \"${cmdline_vars[i]}\""
|
||||||
|
eval "${cmdline_vars[i]}"
|
||||||
|
done
|
||||||
|
|
||||||
notify.enable_colors "$color_scheme"
|
notify.enable_colors "$color_scheme"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user