Blame Scripts/Functions/Render/render_getConfigOption.sh

eb0e14
#!/bin/bash
eb0e14
#
a5b29e
# render_getConfigOption.sh -- This function standardizes the
a5b29e
# configuration fields are retrived from some action-specific
a5b29e
# definitions.
eb0e14
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# WITHOUT ANY WARRANTY; without even the implied warranty of
eb0e14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
eb0e14
# General Public License for more details.
eb0e14
#
eb0e14
# You should have received a copy of the GNU General Public License
eb0e14
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
eb0e14
# ----------------------------------------------------------------------
eb0e14
# $Id$
eb0e14
# ----------------------------------------------------------------------
eb0e14
ab1d67
function render_getConfigOption {
eb0e14
a5b29e
    # Initialize action string.
eb0e14
    local ACTION="$1"
a5b29e
a5b29e
    # Initialize field definition.
eb0e14
    local FIELD="$2"
eb0e14
a5b29e
    # Initialize configuration options.
a5b29e
    local OPTION=''
a5b29e
a5b29e
    # Check action string. The action string must be present in order
a5b29e
    # for this function to work. It provides the information needed to
a5b29e
    # retrive configurantion options from.
eb0e14
    if [[ "$ACTION" == '' ]];then
a5b29e
        cli_printMessage "`gettext "There is no action string to work with."`" --as-error-line
eb0e14
    fi
eb0e14
a5b29e
    # Check field definition. The field definition must match any of
a5b29e
    # the formats specified by the `-f' option of `cut' command.
eb0e14
    if [[ ! "$FIELD" =~ '^([0-9]+|[0-9]+-|-[0-9]+|[0-9]+-[0-9]+)$' ]];then
a5b29e
        cli_printMessage "`gettext "The field definition is not valid."`" --as-error-line
eb0e14
    fi
eb0e14
a5b29e
    # Get configuration option from action string.
a5b29e
    OPTION=$(echo -n "$ACTION" | cut -d: -f${FIELD})
eb0e14
a5b29e
    # Sanitate configuration option retrived from action string.
a5b29e
    OPTION=$(echo -n "${OPTION}" \
eb0e14
        | sed -r 's!^ *!!g' \
eb0e14
        | sed -r 's!( |,|;) *! !g' \
eb0e14
        | sed -r 's! *$!!g')
eb0e14
6de64f
    # Print out the configuration option retrived from action string,
6de64f
    # only if it is not an empty value. Do not use `echo' or `printf'
6de64f
    # built-in commands here. Use the `cli_printMessage' functionality
6de64f
    # instead.  This is required in order to reverse the apostrophe
6de64f
    # codification accomplished when options were retrived from
793c4c
    # command-line (cli_parseArgumentsReDef) in the argument of
6de64f
    # options like `--post-rendition' and `--last-rendition'.
6de64f
    if [[ $OPTION != '' ]];then
6de64f
        cli_printMessage "$OPTION" --as-stdout-line
a5b29e
    fi
a5b29e
eb0e14
}