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:
Davide Madrisan 2012-11-25 23:21:06 +01:00
parent eb0f465be0
commit 29e18765b6
6 changed files with 95 additions and 35 deletions

View File

@ -49,6 +49,15 @@ Changes in version 1.16.0
Remove all the partial .po files and dinamically create a global .pot
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

View File

@ -94,7 +94,7 @@ notify.disable_colors
exit 1; }
. @libdir@/libcfg.lib
# Little helper function for reading args from the commandline.
# it automatically handles -a b and -a=b variants, and returns 1 if
# we need to shift $3.
@ -116,6 +116,8 @@ function read_arg() {
}
args=()
cmdline_vars=()
while (($# > 0)); do
args[${#args[*]}]="$1"
case ${1%%=*} in
@ -131,32 +133,39 @@ while (($# > 0)); do
let "verbose = 2" ;;
-q|--quiet)
let "verbose = 0" ;;
-r|--colorize)
notify.warning $"\
deprecated option"" \`-r|--colorize': "$"use \`--colors' instead"
# for backward compatibility
selected_color_scheme="default" ;;
-h|--help)
let "print_help = 1" ;;
-V|--version)
let "print_version = 1" ;;
--colors)
read_arg selected_color_scheme "$@" ||
{ shift; args[${#args[*]}]="$1"; } ;;
read_arg color_scheme "$@" ||
{ shift; args[${#args[*]}]="$1"; }
notify.debug "color_scheme = \"$color_scheme\""
cmdline_vars[${#cmdline_vars[*]}]="color_scheme=\"$color_scheme\""
;;
-C|--config)
read_arg custom_cfgfile_list "$@" ||
{ shift; args[${#args[*]}]="$1"; } ;;
*) ;;
read_arg cfgfile_list_cmdline "$@" ||
{ shift; args[${#args[*]}]="$1"; }
notify.debug "cfgfile_list_cmdline = \"$cfgfile_list_cmdline\""
;;
*) ;;
esac
shift
done
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\""
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"
notify.enable_colors "$color_scheme"
case "$(( $pck_update + $spec_create + $pck_extract + $config_getvar ))" in
0) [ "$print_help" = "1" ] && autospec.usage 0
@ -172,9 +181,6 @@ case "$(( $pck_update + $spec_create + $pck_extract + $config_getvar ))" in
*) autospec.usage 1 ;;
esac
[ "$logging" = "1" ] && color_scheme="none"
notify.enable_colors "$color_scheme"
# checking for errors in the configuration file
[ "$config_getvar" = 1 ] || config.integrity

View File

@ -116,7 +116,8 @@ function cfg_load_files() {
notify.error $"configuration file not found"": $1"
# select a different list of user configuration files
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
# default configuration files
cfgfile_list=(${default_cfg_list[@]})

View File

@ -110,6 +110,8 @@ frontend_opts: \
notify.debug "[ ${0} ${exec_options} ]\n"
eval set -- "$exec_options"
cmdline_vars=()
while :; do
case $1 in
-x|--extract) ;;
@ -118,9 +120,16 @@ while :; do
--destdir)
destdir="$2"; shift ;;
--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)
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)
let "verbose = 2" ;;
-q|--quiet)
@ -140,8 +149,14 @@ for arg in $@; do
notify.error $"unrecognized option"" -- \`$arg'"
done
notify.debug "custom_cfgfile_list = \"$custom_cfgfile_list\""
cfg_load_files "$custom_cfgfile_list"
cfg_load_files "$cfgfile_list_cmdline"
# 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"

View File

@ -204,6 +204,8 @@ debug,quiet,help,version \
eval set -- "$exec_options"
cmdline_vars=()
while :; do
case $1 in
-u|--update) ;;
@ -237,7 +239,8 @@ while :; do
ftp_server_upload_id="$2"
shift ;;
--changelog)
changelog_commandline="$2"; shift ;;
changelog_cmdline="$2"; shift
notify.debug "changelog_cmdline = \"$changelog_cmdline\"" ;;
--nosrpm)
let "nosrpm = 1" ;;
--norpm)
@ -278,9 +281,16 @@ while :; do
-q|--quiet)
let "verbose = 0" ;;
--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)
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)
usage 0 ;;
-V|--version)
@ -306,15 +316,19 @@ done
notify.debug "${0} ${exec_options}"
#echo -e "[ ${0} \\ \n ${exec_options} ]\n"
notify.debug "changelog_commandline = \"$changelog_commandline\""
if [ -n "$rpm_rootdir" ]; then
[ -d "$rpm_rootdir" ] ||
notify.error $"no such file or directory"": $rpm_rootdir"
fi
notify.debug "custom_cfgfile_list = \"$custom_cfgfile_list\""
cfg_load_files "$custom_cfgfile_list"
cfg_load_files "$cfgfile_list_cmdline"
# 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"
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
local changelog_new
if [ "$changelog_commandline" ]; then
changelog_new="$changelog_commandline"
if [ "$changelog_cmdline" ]; then
changelog_new="$changelog_cmdline"
elif [ "$changelog_userdef" ]; then
changelog_new="$changelog_userdef"
else

View File

@ -172,6 +172,8 @@ frontend_opts: \
notify.debug "[ ${0} ${exec_options} ]\n"
eval set -- "$exec_options"
cmdline_vars=()
while :; do
case $1 in
-s|--source)
@ -198,9 +200,16 @@ while :; do
-q|--quiet)
let "verbose = 0" ;;
--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)
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)
usage 0 ;;
-V|--version)
@ -215,8 +224,14 @@ for arg in $@; do
notify.error $"unrecognized option"" -- \`$arg'"
done
notify.debug "custom_cfgfile_list = \"$custom_cfgfile_list\""
cfg_load_files "$custom_cfgfile_list"
cfg_load_files "$cfgfile_list_cmdline"
# 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"