Blame Scripts/Functions/cli.sh

4c79b5
#!/bin/bash
4c79b5
#
c5b9d2
# cli.sh -- This function initiates centos-art command-line interface.
c5b9d2
# Variables defined in this function are accesible by all other
c5b9d2
# functions. The cli function is the first script executed by
4c79b5
# centos-art command-line onces invoked.
4c79b5
#
2d3646
# 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
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function cli {
4c79b5
cdebd1
    # Initialize global variables.
f19466
    local FUNCNAM=''
c5b9d2
    local FUNCDIR=''
c5b9d2
    local FUNCDIRNAM=''
c5b9d2
    local FUNCSCRIPT=''
c5b9d2
    local FUNCCONFIG=''
f19466
    local ARGUMENTS=''
f19466
49237e
    # Initialize default value to filter flag. The filter flag
49237e
    # (--filter) is used mainly to reduce the number of files to
49237e
    # process. The value of this variable is interpreted as
49237e
    # egrep-posix regular expression.  By default, everything matches.
49237e
    local FLAG_FILTER='.+'
49237e
558b58
    # Initialize default value to verbosity flag. The verbosity flag
476434
    # (--quiet) controls whether centos-art.sh script prints messages
49237e
    # or not. By default, all messages are printed out.
ff1143
    local FLAG_QUIET='false'
ff1143
    
5942a5
    # Initialize default value to answer flag. The answer flag
3ccb0a
    # (--answer-yes) controls whether centos-art.sh script does or
3ccb0a
    # does not pass confirmation request points. By default, it
3ccb0a
    # doesn't.
5942a5
    local FLAG_ANSWER='false'
ff1143
9f0cf5
    # Initialize default value to don't commit changes flag. The don't
9f0cf5
    # commit changes flag (--dont-commit-changes) controls whether
49237e
    # centos-art.sh script syncronizes changes between the central
49237e
    # repository and the working copy. By default, it does.
9f0cf5
    local FLAG_DONT_COMMIT_CHANGES='false'
9f0cf5
49237e
    # Redefine ARGUMENTS variable using current positional parameters. 
793c4c
    cli_parseArgumentsReDef "$@"
f19466
c5b9d2
    # Define function directory (FUNCDIR). The directory path where
c5b9d2
    # functionalities are stored inside the repository.
7b46a4
    FUNCDIR=${CLI_BASEDIR}/Functions
c5b9d2
53a41d
    # Check function name. The function name is critical for
53a41d
    # centos-art.sh script to do something coherent. If it is not
53a41d
    # provided, execute the help functionality and end script
53a41d
    # execution.
53a41d
    if [[ "$1" == '' ]];then
53a41d
        exec ${CLI_BASEDIR}/centos-art.sh help
53a41d
        exit
53a41d
    fi
53a41d
c5b9d2
    # Define function name (FUNCNAM) variable from first command-line
c5b9d2
    # argument.  As convenction we use the first argument to determine
c5b9d2
    # the exact name of functionality to call.
7b03ca
    FUNCNAM=$(cli_getRepoName $1 -f)
c5b9d2
861bb0
    # Define function directory. 
7b03ca
    FUNCDIRNAM=$(cli_getRepoName $FUNCNAM -d)
c5b9d2
861bb0
    # Define function file name.
861bb0
    FUNCSCRIPT=${FUNCDIR}/${FUNCDIRNAM}/${FUNCNAM}.sh
c5b9d2
49237e
    # Check function script execution rights.
6836d6
    cli_checkFiles "${FUNCSCRIPT}" --execution
c5b9d2
861bb0
    # Define function configuration directory. The function
861bb0
    # configuration directory is used to store functionality's
861bb0
    # related files.
861bb0
    FUNCCONFIG=${FUNCDIR}/${FUNCDIRNAM}/Config
c5b9d2
c5b9d2
    # Remove the first argument passed to centos-art.sh command-line
c5b9d2
    # in order to build optional arguments inside functionalities. We
c5b9d2
    # start counting from second argument (inclusive) on.
c5b9d2
    shift 1
c5b9d2
49237e
    # Redefine ARGUMENTS using current positional parameters.
793c4c
    cli_parseArgumentsReDef "$@"
b76c02
b76c02
    # Define default text editors used by centos-art.sh script.
4386e8
    if [[ ! "$EDITOR" =~ '/usr/bin/(vim|emacs|nano)' ]];then
4c79b5
        EDITOR='/usr/bin/vim'
4c79b5
    fi
b76c02
    
49237e
    # Check text editor execution rights.
6836d6
    cli_checkFiles $EDITOR --execution
4c79b5
79b380
    # Go for function initialization. Keep the cli_getFunctions
79b380
    # function calling after all variables and arguments definitions.
be6d51
    cli_getFunctions "${FUNCDIR}/${FUNCDIRNAM}"
4c79b5
4c79b5
}