Blame Scripts/Bash/Functions/init.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# cli.sh -- This function initiates centos-art command-line interface.
878a2b
# Variables defined in this function are accesible by all other
878a2b
# functions. The cli function is the first script executed by
878a2b
# centos-art command-line onces invoked.
878a2b
#
878a2b
# Copyright (C) 2009, 2010, 2011 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 cli {
878a2b
878a2b
    # Initialize global variables.
878a2b
    local CLI_FUNCNAME=''
878a2b
    local CLI_FUNCDIR=''
878a2b
    local CLI_FUNCDIRNAM=''
878a2b
    local CLI_FUNCSCRIPT=''
878a2b
    local ARGUMENTS=''
878a2b
878a2b
    # Initialize default value to filter flag. The filter flag
878a2b
    # (--filter) is used mainly to reduce the number of files to
878a2b
    # process. The value of this variable is interpreted as
878a2b
    # egrep-posix regular expression.  By default, everything matches.
878a2b
    local FLAG_FILTER='.+'
878a2b
878a2b
    # Initialize default value to verbosity flag. The verbosity flag
878a2b
    # (--quiet) controls whether centos-art.sh script prints messages
878a2b
    # or not. By default, all messages are printed out.
878a2b
    local FLAG_QUIET='false'
878a2b
    
878a2b
    # Initialize default value to answer flag. The answer flag
878a2b
    # (--answer-yes) controls whether centos-art.sh script does or
878a2b
    # does not pass confirmation request points. By default, it
878a2b
    # doesn't.
878a2b
    local FLAG_ANSWER='false'
878a2b
878a2b
    # Initialize default value to don't commit changes flag. The don't
878a2b
    # commit changes flag (--dont-commit-changes) controls whether
878a2b
    # centos-art.sh script syncronizes changes between the central
878a2b
    # repository and the working copy. By default, it does.
878a2b
    local FLAG_DONT_COMMIT_CHANGES='false'
878a2b
878a2b
    # Redefine ARGUMENTS variable using current positional parameters. 
878a2b
    cli_parseArgumentsReDef "$@"
878a2b
878a2b
    # Define function directory (CLI_FUNCDIR). The directory path where
878a2b
    # functionalities are stored inside the repository.
878a2b
    CLI_FUNCDIR=${CLI_BASEDIR}/Functions
878a2b
878a2b
    # Check function name. The function name is critical for
878a2b
    # centos-art.sh script to do something coherent. If it is not
878a2b
    # provided, execute the help functionality and end script
878a2b
    # execution.
878a2b
    if [[ "$1" == '' ]];then
878a2b
        exec ${CLI_BASEDIR}/centos-art.sh help
878a2b
        exit
878a2b
    fi
878a2b
878a2b
    # Define function name (CLI_FUNCNAME) variable from first command-line
878a2b
    # argument.  As convenction we use the first argument to determine
878a2b
    # the exact name of functionality to call.
878a2b
    CLI_FUNCNAME=$(cli_getRepoName $1 -f)
878a2b
878a2b
    # Define function directory. 
878a2b
    CLI_FUNCDIRNAM=$(cli_getRepoName $CLI_FUNCNAME -d)
878a2b
878a2b
    # Define function file name.
878a2b
    CLI_FUNCSCRIPT=${CLI_FUNCDIR}/${CLI_FUNCDIRNAM}/${CLI_FUNCNAME}.sh
878a2b
878a2b
    # Check function script execution rights.
878a2b
    cli_checkFiles "${CLI_FUNCSCRIPT}" --execution
878a2b
878a2b
    # Remove the first argument passed to centos-art.sh command-line
878a2b
    # in order to build optional arguments inside functionalities. We
878a2b
    # start counting from second argument (inclusive) on.
878a2b
    shift 1
878a2b
878a2b
    # Redefine ARGUMENTS using current positional parameters.
878a2b
    cli_parseArgumentsReDef "$@"
878a2b
878a2b
    # Define default text editors used by centos-art.sh script.
878a2b
    if [[ ! "$EDITOR" =~ '/usr/bin/(vim|emacs|nano)' ]];then
878a2b
        EDITOR='/usr/bin/vim'
878a2b
    fi
878a2b
    
878a2b
    # Check text editor execution rights.
878a2b
    cli_checkFiles $EDITOR --execution
878a2b
878a2b
    # Go for function initialization. Keep the cli_exportFunctions
878a2b
    # function calling after all variables and arguments definitions.
878a2b
    cli_exportFunctions "${CLI_FUNCDIR}/${CLI_FUNCDIRNAM}"
878a2b
878a2b
    # Execute function.
878a2b
    eval $CLI_FUNCNAME
878a2b
878a2b
}