|
|
4c79b5 |
#!/bin/bash
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# cli.sh -- This function initializes centos-art command line
|
|
|
4c79b5 |
# interface. Variables defined in this function are accesible by all
|
|
|
4c79b5 |
# other functions. The cli function is the first script executed by
|
|
|
4c79b5 |
# centos-art command-line onces invoked.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# Copyright (C) 2009-2010 Alain Reguera Delgado
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# This program is free software; you can redistribute it and/or modify
|
|
|
4c79b5 |
# it under the terms of the GNU General Public License as published by
|
|
|
4c79b5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
|
4c79b5 |
# (at your option) any later version.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# This program is distributed in the hope that it will be useful, but
|
|
|
4c79b5 |
# 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
|
|
|
4c79b5 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
4c79b5 |
# USA.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
4c79b5 |
# $Id: cli.sh 98 2010-09-19 16:01:53Z al $
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function cli {
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define action variable using first argument (lowercase) value.
|
|
|
4c79b5 |
ACTION=$(cli_getRepoName 'f' "$1")
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define option name (OPTIONNAM) and option value (OPTIONVAL)
|
|
|
4c79b5 |
# variables passed as second argument to the command line
|
|
|
4c79b5 |
# interface when the format is `--option=value' without the value
|
|
|
4c79b5 |
# part.
|
|
|
1c1945 |
if [[ "$2" =~ '^--[a-z-]+=.+$' ]];then
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define option name passed in the second argument.
|
|
|
4c79b5 |
OPTIONNAM=$(echo "$2" | cut -d = -f1)
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define option value passed in the second argument.
|
|
|
4c79b5 |
OPTIONVAL=$(echo "$2" | cut -d = -f2-)
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Check option value passed in the second argument.
|
|
|
4c79b5 |
cli_checkOptionValue
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define option name (OPTIONNAM), and option value (OPTIONVAL)
|
|
|
4c79b5 |
# variables passed as second argument to the command line
|
|
|
4c79b5 |
# interface when the format is `--option' without the value part.
|
|
|
1c1945 |
elif [[ "$2" =~ '^--[a-z-]+=?$' ]];then
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define option name passed in the second argument.
|
|
|
4c79b5 |
OPTIONNAM=$(echo "$2" | cut -d = -f1)
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define option value passed in the second argument. Assume
|
|
|
4c79b5 |
# the local path. This saves you some typing when you are
|
|
|
4c79b5 |
# in the place you want to apply your action on.
|
|
|
4c79b5 |
if [[ $(pwd) =~ '^/home/centos/artwork/.+$' ]];then
|
|
|
4c79b5 |
OPTIONVAL=$(pwd)
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
OPTIONVAL='/home/centos/artwork/trunk'
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define default option name (OPTIONNAM), and default option value
|
|
|
4c79b5 |
# (OPTIONVAL) when no second argument is passed to the command
|
|
|
4c79b5 |
# line interface.
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define default option name.
|
|
|
4c79b5 |
OPTIONNAM="default"
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define default option value.
|
|
|
4c79b5 |
if [[ $(pwd) =~ '^/home/centos/artwork/.+$' ]];then
|
|
|
4c79b5 |
OPTIONVAL=$(pwd)
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
OPTIONVAL='/home/centos/artwork/trunk'
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define regular expression (REGEX) used to reduce file
|
|
|
4c79b5 |
# processing. If no regular expression is defined, set regular
|
|
|
4c79b5 |
# expression to match everything.
|
|
|
4c79b5 |
if [[ "$3" =~ '^--filter=.+$' ]];then
|
|
|
4c79b5 |
REGEX=$(echo "$3" | cut -d '=' -f2-)
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
REGEX='.+'
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# If option value plus the filter value (REGEX) points to a valid
|
|
|
4c79b5 |
# file, re-define the option value (OPTIONVAL) using the
|
|
|
4c79b5 |
# directory/file absolute path combination instead. This let you
|
|
|
4c79b5 |
# create documentation entries for files too.
|
|
|
4c79b5 |
if [[ -f $OPTIONVAL/$REGEX ]];then
|
|
|
4c79b5 |
OPTIONVAL=$OPTIONVAL/$REGEX
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define positive answer.
|
|
|
4c79b5 |
Y="`gettext "y"`"
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define negative answer.
|
|
|
4c79b5 |
N="`gettext "N"`"
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define default answer to questions.
|
|
|
4c79b5 |
ANSWER=${N}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define a unique string based on script name and process id used
|
|
|
4c79b5 |
# to create temporal files under /tmp/.
|
|
|
4c79b5 |
FILEID="centos-art$$"
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define text editor used to edit texinfo documentation. Predifine
|
|
|
4c79b5 |
# possible editors paths here to avoid malevolent values. If we do
|
|
|
4c79b5 |
# not create this restriction editor can be set to anything other
|
|
|
4c79b5 |
# than a text editor and in that case be executed when you try to
|
|
|
4c79b5 |
# edit a documentation entry using the `centos-art help --edit'
|
|
|
4c79b5 |
# command.
|
|
|
4c79b5 |
if [[ ! "$EDITOR" =~ '/usr/bin/(emacs|vim|nano)' ]];then
|
|
|
4c79b5 |
EDITOR='/usr/bin/vim'
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Go to defined actions. Keep the cli_getActions function calling
|
|
|
4c79b5 |
# after all variables and arguments definitions. Reason? To make
|
|
|
4c79b5 |
# all variables and arguments definitions available inside
|
|
|
4c79b5 |
# cli_Actions and subsequent function calls inside it.
|
|
|
4c79b5 |
cli_getActions "$@"
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|