From 29e18765b671055b51dd256f5c39fd065aad562a Mon Sep 17 00:00:00 2001 From: Davide Madrisan Date: Sun, 25 Nov 2012 23:21:06 +0100 Subject: [PATCH] autospec, plugins: rework the logic of the command-line options parser Signed-off-by: Davide Madrisan --- ChangeLog | 9 +++++++++ autospec.in | 40 +++++++++++++++++++++++----------------- lib/libcfg.lib.in | 3 ++- plugins/pck-extract.in | 23 +++++++++++++++++++---- plugins/pck-update.in | 32 +++++++++++++++++++++++--------- plugins/spec-create.in | 23 +++++++++++++++++++---- 6 files changed, 95 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 55b4d6b..da5231f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/autospec.in b/autospec.in index 726a16b..0f0f5b9 100644 --- a/autospec.in +++ b/autospec.in @@ -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 diff --git a/lib/libcfg.lib.in b/lib/libcfg.lib.in index dede20b..1d64a57 100644 --- a/lib/libcfg.lib.in +++ b/lib/libcfg.lib.in @@ -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[@]}) diff --git a/plugins/pck-extract.in b/plugins/pck-extract.in index b5d6b0b..0aa895c 100644 --- a/plugins/pck-extract.in +++ b/plugins/pck-extract.in @@ -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" diff --git a/plugins/pck-update.in b/plugins/pck-update.in index b3ba42a..7bd3a40 100644 --- a/plugins/pck-update.in +++ b/plugins/pck-update.in @@ -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 diff --git a/plugins/spec-create.in b/plugins/spec-create.in index 4af26dd..0d0d03b 100644 --- a/plugins/spec-create.in +++ b/plugins/spec-create.in @@ -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"