Blame Scripts/Bash/Functions/Render/render_getConfigOption.sh

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